-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Optimizations for LexicographicTopNs #1603
Conversation
@Override | ||
public int compare(DimValHolder o1, DimValHolder o2) | ||
{ | ||
return comparator.compare(o1.getDimName(), o2.getDimName()); |
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.
Do we need to account for null here?
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.
nvmnd, is done in comparator
Squash and I'm 👍 |
184ee73
to
ceecbbc
Compare
} | ||
|
||
private boolean shouldAdd(String dimName) |
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.
Is it possible to avoid copy pasting the code and reuse the code from the other topnresultbuilders?
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.
they look similar but differ in actual implementation.
final boolean belowThreshold = pQueue.size() < this.threshold; | ||
final boolean belowMax = belowThreshold | ||
|| this.comparator.compare(pQueue.peek().getTopNMetricVal(), dimName) < 0; | ||
return belowMax && comparator.compare(dimName, previousStop) > 0; |
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.
the implementation in TopNNumericResultBuilder
doesn't seem to have the added && comparator.compare(dimName, previousStop) > 0
. Do you mind adding a comment to explain why it's needed?
ceecbbc
to
a3619e6
Compare
final boolean belowMax = belowThreshold | ||
|| this.comparator.compare(pQueue.peek().getTopNMetricVal(), dimName) < 0; | ||
// Only add if dimName is after previousStop | ||
return belowMax && comparator.compare(dimName, previousStop) > 0; |
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.
is it possible to optimize the case where previousStop is null and shortcut the comparison altogether? Seems expensive to call comparator.compare every time?
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.
added the check.
initial review for perf optimizations for lexicographic TopNs fix compilation create map with proper size review comment review comment review comments
a3619e6
to
b8d8a8d
Compare
Optimizations for LexicographicTopNs
-- change storage structure to PriorityQueue
-- Only add to pQueue when required
-- Add Loop unrolling for metrics addition
-- Re-orders Queue on build() call.