-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Remove an allocation from breaker reserve #8851
Conversation
The previous code captured `b`, which required a closure allocation on each call of Reserve. Pre-allocating the closure as a field removes a little bit of allocation from Reserve, which is worthwhile since Reserve is used at high volume in performance-critical sections of the code.
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.
@julz: 0 warnings.
In response to this:
The previous code captured
b
, which required a closure allocation on
each call of Reserve. Pre-allocating the closure as a field removes a
little bit of allocation from Reserve, which is worthwhile since Reserve
is used at high volume in performance-critical sections of the code.Note: simpler options like defining
b.release
as a method rather than
a closure and returning a method reference inReserve
still capture b,
and therefore still allocate :-(./assign @markusthoemmes @vagababov
Benchmarks:
benchmark old ns/op new ns/op delta BenchmarkBreakerReserve/sequential-16 119 92.6 -22.18% BenchmarkBreakerReserve/parallel-16 202 161 -20.30% benchmark old allocs new allocs delta BenchmarkBreakerReserve/sequential-16 1 0 -100.00% BenchmarkBreakerReserve/parallel-16 1 0 -100.00% benchmark old bytes new bytes delta BenchmarkBreakerReserve/sequential-16 16 0 -100.00% BenchmarkBreakerReserve/parallel-16 16 0 -100.00%
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
The following is the coverage report on the affected files.
|
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.
Very nice, I remember not understanding why it allocated too. Thanks for digging this out!
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: julz, 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 |
The following jobs failed:
Failed non-flaky tests preventing automatic retry of pull-knative-serving-integration-tests:
|
/retest |
The previous code captured
b
, which required a closure allocation oneach call of Reserve. Pre-allocating the closure as a field removes a
little bit of allocation from Reserve, which is worthwhile since Reserve
is used at high volume in performance-critical sections of the code.
Note: simpler options like defining
b.release
as a method rather thana closure and returning a method reference in
Reserve
still capture b,and therefore still allocate :-(.
/assign @markusthoemmes @vagababov
Benchmarks: