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

feat(filter): improve perfomance or restoreMetricStringByNameAndLabels #1039

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

almostinf
Copy link
Member

Improve perfomance of restoreMetricStringByNameAndLabels

restoreMetricStringByNameAndLabels is called when parsing metrics, accordingly with a large volume of metrics the number of allocations and perfomance start to be greatly affected

func BenchmarkWriteStringFmt(b *testing.B) {
  var testStr string
  for i := 0; i < b.N; i++ {
    testStr = fmt.Sprintf(";%s=%s", abcde, abcdeabcde)
  }
  _ = testStr
}

func BenchmarkWriteStringPlus(b *testing.B) {
  var testStr string
  for i := 0; i < b.N; i++ {
    testStr = ";" + abcde + "=" + abcdeabcde
  }
  _ = testStr
}

func BenchmarkWriteStringBuilder(b *testing.B) {
  var testStr string
  for i := 0; i < b.N; i++ {
    builder := strings.Builder{}
    builder.WriteString(";")
    builder.WriteString(abcde)
    builder.WriteString("=")
    builder.WriteString(abcdeabcde)
    testStr = builder.String()
  }
  _ = testStr
}

And the result:

BenchmarkWriteStringFmt
BenchmarkWriteStringFmt-12               6402115               182.8 ns/op            56 B/op          3 allocs/op
BenchmarkWriteStringPlus
BenchmarkWriteStringPlus-12             22961696                49.74 ns/op           24 B/op          1 allocs/op
BenchmarkWriteStringBuilder
BenchmarkWriteStringBuilder-12          17070512                66.30 ns/op           32 B/op          2 allocs/op

@almostinf almostinf requested a review from a team as a code owner June 21, 2024 11:00
@almostinf
Copy link
Member Author

/build

@almostinf almostinf merged commit 08fd9a8 into master Jun 24, 2024
7 checks passed
@almostinf almostinf deleted the feat/improve-restore-metric-string branch June 24, 2024 11:52
Copy link

Build and push Docker images with tag: 2024-06-24.08fd9a8

2 similar comments
Copy link

Build and push Docker images with tag: 2024-06-24.08fd9a8

Copy link

Build and push Docker images with tag: 2024-06-24.08fd9a8

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