-
Notifications
You must be signed in to change notification settings - Fork 594
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
More excessively micro micro-optimizations #5616
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5616 +/- ##
===============================================
+ Coverage 87.035% 87.038% +0.003%
- Complexity 31726 31730 +4
===============================================
Files 1943 1943
Lines 146193 146199 +6
Branches 16141 16144 +3
===============================================
+ Hits 127239 127249 +10
+ Misses 13067 13064 -3
+ Partials 5887 5886 -1
|
…impact on the world
b3f376f
to
b194fab
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.
@jamesemery back to you with my comments
@@ -193,18 +193,18 @@ public ReferenceConfidenceModel(final SampleList samples, | |||
final String sampleName = readLikelihoods.getSample(0); | |||
|
|||
final int globalRefOffset = refSpan.getStart() - activeRegion.getExtendedSpan().getStart(); | |||
for ( final ReadPileup pileup : refPileups ) { | |||
for (int i = 0, size = refPileups.size(); i < size; i++) { |
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.
Declare refPileupsSize
as a final var before the loop instead of using multiple initialization within the loop.
@@ -193,18 +193,18 @@ public ReferenceConfidenceModel(final SampleList samples, | |||
final String sampleName = readLikelihoods.getSample(0); | |||
|
|||
final int globalRefOffset = refSpan.getStart() - activeRegion.getExtendedSpan().getStart(); | |||
for ( final ReadPileup pileup : refPileups ) { | |||
for (int i = 0, size = refPileups.size(); i < size; i++) { | |||
ReadPileup pileup = refPileups.get(i); |
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.
final
final int position = call != null ? call.getStart() : curPos.getStart(); | ||
return priorList.stream().filter(vc -> position == vc.getStart()).collect(Collectors.toList()); | ||
List<VariantContext> list = new ArrayList<>(priorList.size()); |
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.
final
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.
And choose a more descriptive name than list
. How about matchingPriors
?
final int position = call != null ? call.getStart() : curPos.getStart(); | ||
return priorList.stream().filter(vc -> position == vc.getStart()).collect(Collectors.toList()); | ||
List<VariantContext> list = new ArrayList<>(priorList.size()); | ||
for (int i = 0, size = priorList.size(); i < size; i++) { |
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.
Declare priorListSize
as a final var before the loop instead of using multiple initialization within the loop.
final int position = call != null ? call.getStart() : curPos.getStart(); | ||
return priorList.stream().filter(vc -> position == vc.getStart()).collect(Collectors.toList()); |
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.
Add a comment that this method is implemented with an old-school for loop instead of streaming for performance reasons (otherwise, someone will probably come along in 2 years and undo this).
@droazen Responded to comments, note that i added a further escape condition where getMatchingPriors is avoided altogether if the VCpriors list is empty. Remember that this method is in a performance sensitive part of the code so every little bit of speed counts. |
@jamesemery You have a compiler error on the latest version of this branch:
|
@droazen fixed, sorry about that |
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.
Two minor additional comments -- back to @jamesemery. Merge after addressing them and tests pass.
@@ -193,18 +193,19 @@ public ReferenceConfidenceModel(final SampleList samples, | |||
final String sampleName = readLikelihoods.getSample(0); | |||
|
|||
final int globalRefOffset = refSpan.getStart() - activeRegion.getExtendedSpan().getStart(); | |||
for ( final ReadPileup pileup : refPileups ) { | |||
final int refPileupsSize = refPileups.size(); | |||
for (int i = 0; i < refPileupsSize; i++) { |
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.
Add comment here that the old-school for loop is intentional (for-each was found to show up on the profiler).
final int position = call != null ? call.getStart() : curPos.getStart(); | ||
return priorList.stream().filter(vc -> position == vc.getStart()).collect(Collectors.toList()); | ||
final List<VariantContext> matchedPriors = new ArrayList<>(priorList.size()); | ||
// NOTE: a for loop is used here because this method ends up being called per-pileup, per-read and thus using faster alternates saves runtime |
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.
" thus using faster alternates saves runtime" -> "using a loop instead of streaming saves runtime"
These methods were showing up as time syncs on the profile for #5607
I ran these a few times vs. its root branch, its probably a small improvement in runtime over this chr15 snippet of an exome on my local machine:
#5607:
This branch:
Depends On #5607