Skip to content

Speed up label escaping #800

Description

@jdmarshall

On the back of #798, there is now an opportunity to escape label values once at insert time rather than on every metrics call.

The metrics call is a high priority target for both time and space improvements. When I first came to the project, it was the most common complaint in the issue backlog. We have managed to speed up everything but this part. Collection is ~20% faster, aggregation 2.4x faster, but metrics are only a couple % faster.

With the introduction of #insert, we should be able to move the escapeString() call to insert. This could be done two ways:

  1. change the labels to only be escaped labels
  2. store the escaped form of the labels beside the original form

Number 2 may be more compatible, and since most strings do not need to be escaped in the first place, represent only a small increase in memory usage.

This work also may reduce or remove the need for the label cache in the Registry. Despite the use of a WeakMap for storage, this does represent a memory cost, and if the label concatenation is cheaper, then it's worth also considering whether the added overhead of the lookups is really worth the extra space and code, or whether the whole thing can be deleted.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions