Skip to content

cache actortype label in CommonLabels - #1328

Open
brevin-yoke wants to merge 1 commit into
asynkron:devfrom
brevin-yoke:dev
Open

brevin-yoke wants to merge 1 commit into
asynkron:devfrom
brevin-yoke:dev

Conversation

@brevin-yoke

Copy link
Copy Markdown

CommonLabels computed the actor type label on every metric emission via
fmt.Sprintf("%T", ...) followed by strings.Replace, incurring reflection
and string allocations on a hot path.

Since the label value is constant per concrete actor type, cache it in a
sync.Map keyed by reflect.Type and compute it only once per type. Use
reflect.TypeOf(...).String() in place of fmt.Sprintf to produce the same
output, and guard against a nil actor to preserve the previous ""
behavior.

CommonLabels computed the actor type label on every metric emission via
  fmt.Sprintf("%T", ...) followed by strings.Replace, incurring reflection
  and string allocations on a hot path.

  Since the label value is constant per concrete actor type, cache it in a
  sync.Map keyed by reflect.Type and compute it only once per type. Use
  reflect.TypeOf(...).String() in place of fmt.Sprintf to produce the same
  output, and guard against a nil actor to preserve the previous "<nil>"
  behavior.
@CLAassistant

CLAassistant commented Jul 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants