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

Label matcher optimizations #8658

Closed
wants to merge 8 commits into from

Conversation

MasslessParticle
Copy link
Contributor

@MasslessParticle MasslessParticle commented Feb 28, 2023

These are some low-hanging optimizations to regex label matchers that already exist for our line-filter matchers:

  • Replace .* matchers with a noop
  • Replace .+ with `len(value) > 0
  • Rewrite greedy regexes to be non-greedy
  • replace literals with strings.Contain

Benchmarks:

Replace .* with noop
name            old time/op    new time/op    delta
EmptyFilters-8    45.2ns ± 3%     1.8ns ± 3%  -95.93%  (p=0.000 n=8+8)

name            old alloc/op   new alloc/op   delta
EmptyFilters-8     0.00B          0.00B          ~     (all equal)

name            old allocs/op  new allocs/op  delta
EmptyFilters-8      0.00           0.00          ~     (all equal)
Replace .+ with len > 0
name             old time/op    new time/op    delta
ExistsFilters-8    10.6ns ±13%     4.5ns ± 8%  -57.78%  (p=0.000 n=10+10)

name             old alloc/op   new alloc/op   delta
ExistsFilters-8     0.00B          0.00B          ~     (all equal)

name             old allocs/op  new allocs/op  delta
ExistsFilters-8      0.00           0.00          ~     (all equal)
Replace literal with strings.Contain
name              old time/op    new time/op    delta
LiteralFilters-8    10.6ns ± 8%     6.0ns ± 1%  -43.50%  (p=0.000 n=10+8)

name              old alloc/op   new alloc/op   delta
LiteralFilters-8     0.00B          0.00B          ~     (all equal)

name              old allocs/op  new allocs/op  delta
LiteralFilters-8      0.00           0.00          ~     (all equal)

greedy -> non-greedy optimizations are benchmarked in this PR: #4775

@MasslessParticle MasslessParticle requested a review from a team as a code owner February 28, 2023 20:32
@MasslessParticle MasslessParticle marked this pull request as draft February 28, 2023 21:35
Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looks great.

@MasslessParticle
Copy link
Contributor Author

This draft is superseded by: #8659 which reuses our optimized line filters as label filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants