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
Refactor set.SliceSubsetOf #25559
Refactor set.SliceSubsetOf #25559
Conversation
6b2d602
to
b306002
Compare
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.
Thank you!
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.
Nice! Benchmarks between the new implementation and the one it replaces?
/test Job 'Cilium-PR-K8s-1.26-kernel-net-next' failed: Click to show.Test Name
Failure Output
Jenkins URL: https://jenkins.cilium.io/job/Cilium-PR-K8s-1.26-kernel-net-next/103/ If it is a flake and a GitHub issue doesn't already exist to track it, comment Then please upload the Jenkins artifacts to that issue. |
b306002
to
d19e797
Compare
I've added a commit with a benchmark.
The number of allocations increased, but the total amount of allocated memory lowered. |
/test Job 'Cilium-PR-K8s-1.26-kernel-net-next' failed: Click to show.Test Name
Failure Output
Jenkins URL: https://jenkins.cilium.io/job/Cilium-PR-K8s-1.26-kernel-net-next/154/ If it is a flake and a GitHub issue doesn't already exist to track it, comment Then please upload the Jenkins artifacts to that issue. |
Needs a rebase |
d19e797
to
64cc1c6
Compare
pkg/set has a method to verify if a given slice is a subset of another. Being an utility function about slice, it is moved in the pkg/slices package. Also, the method is modified to leverage type parameters, and broken down to expose the diff logic as a separate method, to higher the chances of being reused throughout the codebase. Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
The only method exported has been superseded by slices.Subset so the package can be removed. Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
Add a benchmark to measure the performance of the SubsetOf function. Below the benchstat comparison of the current implementation against the old set.SliceSubsetOf: name old time/op new time/op delta SubsetOf/64-512-8 15.3µs ±35% 14.6µs ±27% ~ (p=0.134 n=20+20) SubsetOf/128-512-8 24.4µs ± 5% 22.6µs ± 4% -7.47% (p=0.000 n=18+17) SubsetOf/256-2048-8 88.3µs ± 7% 81.0µs ± 6% -8.28% (p=0.000 n=18+19) SubsetOf/512-2048-8 110µs ± 5% 98µs ± 7% -10.24% (p=0.000 n=20+20) SubsetOf/1024-8192-8 358µs ± 4% 318µs ± 5% -11.25% (p=0.000 n=19+20) SubsetOf/2048-8192-8 469µs ± 5% 423µs ±10% -9.72% (p=0.000 n=20+19) name old alloc/op new alloc/op delta SubsetOf/64-512-8 28.7kB ± 0% 23.2kB ± 0% -19.10% (p=0.000 n=20+20) SubsetOf/128-512-8 28.8kB ± 0% 25.9kB ± 0% -9.97% (p=0.000 n=19+16) SubsetOf/256-2048-8 115kB ± 0% 92kB ± 0% -19.62% (p=0.000 n=19+20) SubsetOf/512-2048-8 115kB ± 0% 103kB ± 0% -10.78% (p=0.000 n=19+16) SubsetOf/1024-8192-8 459kB ± 0% 360kB ± 0% -21.42% (p=0.000 n=18+17) SubsetOf/2048-8192-8 460kB ± 0% 402kB ± 0% -12.59% (p=0.000 n=20+17) name old allocs/op new allocs/op delta SubsetOf/64-512-8 2.00 ± 0% 4.00 ± 0% +100.00% (p=0.000 n=20+20) SubsetOf/128-512-8 4.65 ±57% 5.55 ±28% +19.35% (p=0.028 n=20+20) SubsetOf/256-2048-8 2.00 ± 0% 4.00 ± 0% +100.00% (p=0.000 n=19+20) SubsetOf/512-2048-8 6.45 ±24% 7.75 ±10% +20.16% (p=0.000 n=20+16) SubsetOf/1024-8192-8 2.17 ±38% 4.00 ± 0% +84.62% (p=0.000 n=18+17) SubsetOf/2048-8192-8 8.65 ± 8% 10.00 ± 0% +15.61% (p=0.000 n=20+17) Signed-off-by: Fabio Falzoi <fabio.falzoi@isovalent.com>
64cc1c6
to
24e9e2f
Compare
👍 |
/test |
CI is green and reviews are in, marking ready-to-merge. |
pkg/set has a method to verify if a given slice is a subset of another. Being an utility function about slices, it is moved in the pkg/slices package.
Also, the method is modified to leverage type parameters, and broken down to expose the diff logic as a separate method, to higher the chances of being reused throughout the codebase.
The algorithm used for the new
slices.Diff
andslices.SubsetOf
differ from the previous semantic in a detail: they do not consider duplicates. IOW, the input slices are treated as sets. This is fine with the current usage of the method and in case the opposite semantic will be needed in the future, it'll be possible to add a new method with a different algorithm.