-
Notifications
You must be signed in to change notification settings - Fork 373
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
Do not construct intermediate sets when calculating union of multiple sets #1938
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1938 +/- ##
==========================================
- Coverage 62.49% 58.61% -3.88%
==========================================
Files 202 203 +1
Lines 17480 17482 +2
==========================================
- Hits 10924 10247 -677
- Misses 5388 6120 +732
+ Partials 1168 1115 -53
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/test-all |
/test-integration |
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.
LGTM
pkg/util/sets/string.go
Outdated
// Merge(s1, s2) = {a1, a2, a3, a4, a5} | ||
// s1 = {a1, a2, a3, a4, a5} | ||
// | ||
// It supersedes s1.Union(s2) when constructing a new sets is not the intention. |
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.
s/a new sets/a new set
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.
done, thanks
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 optimization!
… sets An AddressGroup can be shared by multiple NetworkPolicies and its span is the union of the NetworkPolicies'. The syncAddressGroup method uses "Union" method to calculate the union set. However, the method always create a new sets and copies the original items when traversing each set. This performs badly when the number of the NetworkPolicies increase and the span is big. This patch optimizes it by using a "Merge" function to avoid above cost. The benchmark impact is as below when there are 1000 NetworkPolicies sharing the AddressGroup and the span is 1000 Nodes: name old time/op new time/op delta SyncAddressGroup-48 417µs ± 4% 326µs ± 4% -21.91% (p=0.008 n=5+5) name old alloc/op new alloc/op delta SyncAddressGroup-48 98.9kB ± 0% 51.1kB ± 1% -48.27% (p=0.008 n=5+5) name old allocs/op new allocs/op delta SyncAddressGroup-48 1.05k ± 0% 0.05k ± 8% -94.78% (p=0.008 n=5+5)
/test-all |
Merging it as jenkins-windows-networkpolicy succeeded before I fixed the typo. |
… sets (antrea-io#1938) An AddressGroup can be shared by multiple NetworkPolicies and its span is the union of the NetworkPolicies'. The syncAddressGroup method uses "Union" method to calculate the union set. However, the method always create a new sets and copies the original items when traversing each set. This performs badly when the number of the NetworkPolicies increase and the span is big. This patch optimizes it by using a "Merge" function to avoid above cost. The benchmark impact is as below when there are 1000 NetworkPolicies sharing the AddressGroup and the span is 1000 Nodes: name old time/op new time/op delta SyncAddressGroup-48 417µs ± 4% 326µs ± 4% -21.91% (p=0.008 n=5+5) name old alloc/op new alloc/op delta SyncAddressGroup-48 98.9kB ± 0% 51.1kB ± 1% -48.27% (p=0.008 n=5+5) name old allocs/op new allocs/op delta SyncAddressGroup-48 1.05k ± 0% 0.05k ± 8% -94.78% (p=0.008 n=5+5)
An AddressGroup can be shared by multiple NetworkPolicies and its span
is the union of the NetworkPolicies'. The syncAddressGroup method uses
"Union" method to calculate the union set. However, the method always
create a new sets and copies the original items when traversing each
set. This performs badly when the number of the NetworkPolicies increase
and the span is big.
This patch optimizes it by using a "Merge" function to avoid above cost.
The benchmark impact is as below when there are 1000 NetworkPolicies
sharing the AddressGroup and the span is 1000 Nodes: