Skip to content

Builder pattern using Tags leads to high CPU overhead #4052

Open
@DanielThomas

Description

We discovered some significant CPU hotspots in a service and found several places in our frameworks that were doing a significant amount of unnecessary work due to the sort/dedup on every Tags class operation. In our case we were either using Tags as a builder with up to a dozen calls to Tags::and or has several calls to tags(String, String) on the builders:

intrumentDataFetcher

Appears when this commit landed it switched all builders to useTags internally, so incur the sort/dedup penalty for every call, making building tags quite expensive:

b7bbea3#diff-a64eec4db3aaf5a50e01e46efed55b3eecb772bcbe0ad929ef59b455c7a5ec2c

This makes Tags a poor choice for intermediate Tags state and if sort/dedupe can't be avoided, there should probably be a mutable builder class backing these usages instead. If that overhead can't be avoided, I'd argue that the builder-style methods on Tags should be deprecated, because it's easy to get into trouble and not realise it.

Environment

  • Micrometer version 1.11.3

To Reproduce

Use multiple calls to Tags::and and note the overhead.

Expected behavior

Creating multiple tags has as little overhead as possible.

Additional context

Netflix/dgs-framework#1612

Metadata

Assignees

No one assigned

    Labels

    performanceIssues related to general performancewaiting for teamAn issue we need members of the team to review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions