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

Remove an allocation from breaker reserve #8851

Merged
merged 1 commit into from
Jul 30, 2020

Conversation

julz
Copy link
Member

@julz julz commented Jul 30, 2020

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 in Reserve 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%

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.
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 30, 2020
@knative-prow-robot knative-prow-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 30, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a 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 in Reserve 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.

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/queue/breaker.go 98.7% 98.7% 0.0

Copy link
Contributor

@markusthoemmes markusthoemmes left a 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

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 30, 2020
@knative-prow-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 30, 2020
@knative-test-reporter-robot

The following jobs failed:

Test name Triggers Retries
pull-knative-serving-integration-tests 0/3

Failed non-flaky tests preventing automatic retry of pull-knative-serving-integration-tests:

test/conformance/api/v1.TestContainerExitingMsg

@julz
Copy link
Member Author

julz commented Jul 30, 2020

/retest

@knative-prow-robot knative-prow-robot merged commit d8021ee into knative:master Jul 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/networking cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants