-
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
A caching, log(n) complexity report merger #1418
Conversation
func (ns byID) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] } | ||
func (ns byID) Less(i, j int) bool { return ns[i].id < ns[j].id } | ||
|
||
func hash(_1, _2 string) string { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
6d92ce2
to
16928f1
Compare
for _, tr := range c.reports { | ||
rpt = rpt.Merge(tr.report) | ||
id.Write([]byte(tr.report.ID)) | ||
rpts = append(rpts, tr.report) | ||
} |
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.
You don't really need the cache if you just hold a pointer to the root of the tree (i.e. the "current report") |
How so? The algorithm would look very different (have to build and diff two trees). Also I don't know how that would work in the multitenant case. I actually remove the left & right pointers from the node in the latest rev... |
16928f1
to
6c7ca90
Compare
@paulbellamy I'm more concerned about the algorithm TBH. I sort the reports by ID and then take each pair iteratively. As the IDs are random, this means removing a single report will mean we have to re-merge 1/2 the reports again (as they will all 'shift up' by one). I think a better approach might be to subdivide the address space in two each time, more top-down than bottom up. WDYT? |
6c7ca90
to
215991a
Compare
@paulbellamy WDYT? |
215991a
to
b4f3ae6
Compare
I'd be interested in seeing a benchmark of a large number of report merges before/after this change. Edit both with/without the caching |
I'm also curious about the choice of branching factor. i.e. why a binary tree, not e.g. 32 leaf nodes? |
No particular reason; the branching factor is just falls out as a constant factor in the big-o anyway. |
Also merge is binary. |
0bacaaa
to
d1528c7
Compare
|
d1528c7
to
2f54a43
Compare
// Define how to merge two nodes together. The result of merging | ||
// two reports is cached. | ||
hits := 0 | ||
misses := 0 |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
2f54a43
to
54a760a
Compare
@paulbellamy PTAL |
Contains #1398
With this, the vast majority (7 of 8s) of CPU is spent decoding reports.