-
Notifications
You must be signed in to change notification settings - Fork 712
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
Optimise merge where one side is a subset of the other #3253
Conversation
report/latest_map_generated.go
Outdated
case j >= len(n) || m[i].key < n[j].key: | ||
i++ | ||
case m[i].key == n[j].key: | ||
if m[i].Timestamp.Before(n[j].Timestamp) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
report/string_set.go
Outdated
|
||
for i < len(s) { | ||
switch { | ||
case j >= len(other) || s[i] < other[j]: |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
I suggest cherry-picking de47a0e (Less verbose string dump) onto master, since it's a bit of a distraction in this PR. |
Add a test case where one input is longer than the other; also run each case both ways round. Omit the case which was already the reverse of another.
So that we have equal chance of merging older into newer or vice-versa
3886809
to
4ddce89
Compare
This PR is ready for review again. |
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.
A couple of niggles which would be worth addressing. Other than that, LGTM.
report/latest_map_generated.go
Outdated
if len(n) > lenm { | ||
m, n, lenm = n, m, len(n) //swap so m is always at least as long as n | ||
} else if len(n) == lenm && m[0].Timestamp.Before(n[0].Timestamp) { | ||
m, n = n, m // swap equal-length arrays so first element of m is newer |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Swap the two maps so we are merging older into later.
If we run out of things to look at in the other map, return quickly. Also move the equal-key case above the less-than case, since maps with equal keys are the common case when merging.
Make StringSet.Merge() work like StringLatestMap.Merge()
4ddce89
to
692214b
Compare
This is beneficial because Scope very often merges multiple versions of the same node over time that have exactly the same labels, tags, etc., so we detect this and avoid copying.
This PR covers just three data structures -
StringSet
,StringLatestMap
andNodeControlDataLatestMap
- which benefit the most in profiles.All three now use the same loop structure to merge. The loop is coded twice: once as far as we can get without changing the result, and then again after allocating space for a new return value. If we got all the way to the end without changing anything, then return what we already have.
StringSet
is mainly used inSets
where it benefits to avoid assigning to its map, so add anunchanged
return.Before (best of five):
After: