Skip to content

Conversation

@jpbetz
Copy link
Contributor

@jpbetz jpbetz commented Jan 31, 2020

valueReflect uses 65% less CPU and 85% less allocations that valueUnstructured for ConvertToTyped, but for TypedValue.Compare it performs much worse:

BEFORE:
baseline: TypedValue.Compare using valueUnstructured
test variant: TypedValue.Compare using valueReflect

name               old time/op    new time/op    delta
Compare/Pod           100µs ± 3%     195µs ± 1%   +95.19%  (p=0.008 n=5+5)
Compare/Node          166µs ± 9%     280µs ± 0%   +68.38%  (p=0.008 n=5+5)
Compare/Endpoints    1.10ms ± 5%    0.02ms ± 2%   -98.39%  (p=0.008 n=5+5)

name               old alloc/op   new alloc/op   delta
Compare/Pod          11.3kB ± 0%    21.8kB ± 0%   +92.83%  (p=0.016 n=5+4)
Compare/Node         17.1kB ± 0%    40.7kB ± 0%  +137.37%  (p=0.008 n=5+5)
Compare/Endpoints    65.5kB ± 0%     2.6kB ± 0%   -96.03%  (p=0.008 n=5+5)

name               old allocs/op  new allocs/op  delta
Compare/Pod             391 ± 0%       573 ± 0%   +46.55%  (p=0.008 n=5+5)
Compare/Node            577 ± 0%      1101 ± 0%   +90.81%  (p=0.008 n=5+5)
Compare/Endpoints     2.05k ± 0%     0.07k ± 0%   -96.58%  (p=0.008 n=5+5)

This optimizes valueReflect for TypedValue.Compare by:

  • Optimizing equals checks for lists
  • Introducing a Map.Zip function that is used by typed.merge, typed.compare, map equality and map compare operations
  • Optimizing Map.Zip for valueReflect
  • Recycling all value.Map and value.List objects since these are not free for valueReflect

With these changes, valueReflect still underperforms valueUnstructured (except for endpoints, where it really shines), but is is considerably closer.

AFTER:

name               old time/op    new time/op    delta
Compare/Pod           100µs ± 3%     127µs ± 3%  +26.95%  (p=0.008 n=5+5)
Compare/Node          166µs ± 9%     188µs ± 4%  +13.01%  (p=0.008 n=5+5)
Compare/Endpoints    1.10ms ± 5%    0.01ms ± 6%  -98.98%  (p=0.008 n=5+5)

name               old alloc/op   new alloc/op   delta
Compare/Pod          11.3kB ± 0%    14.2kB ± 0%  +25.66%  (p=0.016 n=5+4)
Compare/Node         17.1kB ± 0%    25.4kB ± 0%  +48.19%  (p=0.008 n=5+5)
Compare/Endpoints    65.5kB ± 0%     1.7kB ± 0%  -97.37%  (p=0.008 n=5+5)

name               old allocs/op  new allocs/op  delta
Compare/Pod             391 ± 0%       433 ± 0%  +10.74%  (p=0.008 n=5+5)
Compare/Node            577 ± 0%       795 ± 0%  +37.78%  (p=0.008 n=5+5)
Compare/Endpoints     2.05k ± 0%     0.05k ± 0%  -97.36%  (p=0.008 n=5+5)

For the portion of the Update changed by introducing server side apply, where ConvertToTyped and TypedValue.Compare are called in series, the net gain is still a substantial win, with ~52% less CPU and 60% less allocations.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 31, 2020
@jpbetz jpbetz force-pushed the compare-optimizations branch from e794a6f to 1a53920 Compare January 31, 2020 23:08
@jpbetz
Copy link
Contributor Author

jpbetz commented Jan 31, 2020

/assign @apelisse
/cc @jennybuckley
/sig api-machinery

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jan 31, 2020
@jpbetz
Copy link
Contributor Author

jpbetz commented Feb 5, 2020

Thanks @apelisse! Feedback applied.

@apelisse
Copy link
Contributor

apelisse commented Feb 5, 2020

Maybe squash and then we're good.

@jpbetz jpbetz force-pushed the compare-optimizations branch from d6641ff to 719dc37 Compare February 6, 2020 02:40
@jpbetz
Copy link
Contributor Author

jpbetz commented Feb 6, 2020

squashed

@apelisse
Copy link
Contributor

apelisse commented Feb 6, 2020

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 6, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse, jpbetz

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 6, 2020
@k8s-ci-robot k8s-ci-robot merged commit b8515d0 into kubernetes-sigs:master Feb 6, 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants