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

[mutation] Cache tester in AssignMetadata like we do in Assign mutators #1442

Merged
merged 2 commits into from Jul 17, 2021

Conversation

willbeason
Copy link
Member

@willbeason willbeason commented Jul 14, 2021

Note: depends on #1441

Per findings in #1441, we can greatly improve the speed of AssignMetadata.Mutate by caching the tester instead of recreating it every time we call Mutate.

This reduces the runtime when no mutation is made by 97%, and when mutations are made by 30%!

$ for i in {1..20}; do echo $i; go test github.com/open-policy-agent/gatekeeper/pkg/mutation/mutators --bench=BenchmarkAssignMetadata >> before.out; done
$ git checkout benchmark-metadata-2
$ for i in {1..20}; do echo $i; go test github.com/open-policy-agent/gatekeeper/pkg/mutation/mutators --bench=BenchmarkAssignMetadata >> after.out; done
$ benchstat before.out after.out 

name                        old time/op  new time/op  delta
AssignMetadataMutator_Always-12    6.64µs ± 2%  4.70µs ± 1%  -29.22%  (p=0.000 n=19+19)
AssignMetadataMutator_Never-12     1.84µs ± 6%  0.05µs ± 0%  -97.04%  (p=0.000 n=19+18)

I'll send a separate PR which removes the unnecessary json unmarshalling in the case where we perform the mutation, once/if #1439 is merged.

@willbeason willbeason self-assigned this Jul 14, 2021
@willbeason willbeason marked this pull request as draft July 14, 2021 20:16
@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2021

Codecov Report

Merging #1442 (458774d) into master (152e102) will increase coverage by 0.25%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1442      +/-   ##
==========================================
+ Coverage   50.35%   50.60%   +0.25%     
==========================================
  Files          77       77              
  Lines        5108     5110       +2     
==========================================
+ Hits         2572     2586      +14     
+ Misses       2185     2174      -11     
+ Partials      351      350       -1     
Flag Coverage Δ
unittests 50.60% <50.00%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/mutation/mutators/assignmeta_mutator.go 47.82% <50.00%> (+4.54%) ⬆️
...onstrainttemplate/constrainttemplate_controller.go 54.69% <0.00%> (+1.61%) ⬆️
pkg/readiness/object_tracker.go 82.60% <0.00%> (+1.63%) ⬆️
pkg/controller/assign/assign_controller.go 51.72% <0.00%> (+1.72%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 152e102...458774d. Read the comment docs.

@willbeason willbeason marked this pull request as ready for review July 14, 2021 20:30
@willbeason willbeason changed the title [mutation] Benchmark metadata 2 [mutation] Cache tester in AssignMetadata like we do in Assign mutators Jul 14, 2021
@willbeason willbeason force-pushed the benchmark-metadata-2 branch 2 times, most recently from a1073f0 to e9b0bf6 Compare July 14, 2021 20:40
Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

LGTM

@shomron @sozercan LGTY?

Will Beason added 2 commits July 16, 2021 07:29
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
@willbeason willbeason merged commit 938edcd into open-policy-agent:master Jul 17, 2021
@willbeason willbeason deleted the benchmark-metadata-2 branch July 17, 2021 03:57
julianKatz pushed a commit to julianKatz/gatekeeper that referenced this pull request Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants