Skip to content

Avoid calling URI.toString when populating tracing span tags #3308

@GnawNom

Description

@GnawNom

Feature Request

Looking at flame graphs for our service we found 3% of our cpu time was spent on calling toString for a string that should already exist.

https://github.com/redis/lettuce/blob/main/src/main/java/io/lettuce/core/protocol/CommandHandler.java#L495

Is your feature request related to a problem? Please describe

Current implementation wastes CPU cycles

Describe the solution you'd like

redisUriStr is passed to create a URI class and then toString is called on the URI class to populate the span tag for server.address. We can avoid this toString call and pass redisUriStr directly for server.address. Unless the toString produces a different string from the one passed in to create the URI class, I think this is a reasonable change.

Describe alternatives you've considered

An alternative is to cache the URI object and resulting strings, but that seems like overkill. If this channel attribute is immutable (channel.attr(ConnectionBuilder.REDIS_URI).get();) we could probably extend the change to cache all the span tags we generate if the URI is not going to change for the channel. In our flame graph analysis another 3% of wasted CPU time was in instantiating this URI class every time span tags need to be populated.

Teachability, Documentation, Adoption, Migration Strategy

Not sure, not really a user facing feature. More of an optimization. Let me know if this belongs under a different category from Feature Request

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions