-
Notifications
You must be signed in to change notification settings - Fork 331
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
Fix excessive allocation in the resource metrics #1964
Fix excessive allocation in the resource metrics #1964
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: markusthoemmes The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov Report
@@ Coverage Diff @@
## master #1964 +/- ##
==========================================
+ Coverage 68.92% 68.94% +0.01%
==========================================
Files 209 209
Lines 8778 8790 +12
==========================================
+ Hits 6050 6060 +10
- Misses 2453 2454 +1
- Partials 275 276 +1
Continue to review full report at Codecov.
|
metrics/resource_view.go
Outdated
var s strings.Builder | ||
writeKV := func(key, value string) { | ||
// We use byte values 1 and 2 to avoid colliding with valid resource labels | ||
// and to make unpacking easy | ||
s.WriteByte('\x01') | ||
s.WriteString(key) | ||
s.WriteByte('\x02') | ||
s.WriteString(value) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if at this point func writeKV(Builder, string, string)
isn't better, or definitely more readable.
Shouldn't it save an allocation, since otherwise it'll dynamically create the lambda to bind it to s
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda doesn't escape apparently. Moving it out works too though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/lgtm |
Changes
Through a bit of cleanup work in Knative Serving, it got kinda apparent that our metric recording calls are kinda expensive. I triaged it down to the
resourceToKey
being quite expensive.Discussing with @evankanderson, we came up with this quick fix to make the allocations of the functions much more reasonable without coming up with a different way of handling the keys here altogether.
Benchmark results
/assign @evankanderson