Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Estimate StringBuilder capacity for exported names #919

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Feb 22, 2024

  1. Estimate StringBuilder capacity for exported names

    When we generate metric names, we use the default `StringBuilder`
    constructor, which allocates a _16 character_ buffer.
    
    Most metrics will exceed this, especially when we start adding
    attributes to it.
    
    This causes `StringBuilder` to "grow", automatically, by allocating a
    new array and copying its contents over to it. Each time it only grows
    enough to contain the `append`ed String, which means we need to grow on
    almost every `append` call.
    
    While allocating new memory is cheap in the JVM, copying memory is not.
    These copies add up, especially with a large number of long-named
    metrics with many attributes.
    
    Instead, we can calculate the necessary capacity of the `StringBuilder`
    up-front, which should avoid doing any copying during `append`.
    
    Signed-off-by: Nick Telford <nick.telford@gmail.com>
    nicktelford committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    c8d2b3c View commit details
    Browse the repository at this point in the history