-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Remove some redundant ref-counting from SearchHits #124948
base: main
Are you sure you want to change the base?
Remove some redundant ref-counting from SearchHits #124948
Conversation
Remove ref-counting that is obviously redundant because of clear ownership transfers from `SearchHits`.
Pinging @elastic/es-search-foundations (Team:Search Foundations) |
SearchResponse theResponse = mockSearchPhaseContext.searchResponse.get(); | ||
assertNotNull(theResponse); | ||
assertEquals(numInnerHits, theResponse.getHits().getHits()[0].getInnerHits().size()); | ||
ExpandSearchPhase phase = newExpandSearchPhase( |
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.
This stuff is what blows up the LoC changed in this PR but I felt it best to inline these values still since their lifecycle is now bound to the SearchResponseSections
.
@@ -252,6 +252,7 @@ public boolean decRef() { | |||
} | |||
|
|||
private void deallocate() { | |||
var hits = this.hits; |
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.
Just saving the memory reference, turns out this was what made this method show up in profiling.
ProfileResult profileResult = profiler.finish(); | ||
// Only set the shardResults if building search hits was successful | ||
if (hits != null) { | ||
context.fetchResult().shardResult(hits, profileResult); |
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.
For ease of reviewing: this is the only production callsite where we pass a pooled instance into shardResult
so changing shardResult(..)
and this logic is relatively obviously safe.
} | ||
} | ||
|
||
private static void mergeSuggest( | ||
ReducedQueryPhase reducedQueryPhase, | ||
AtomicArray<? extends SearchPhaseResult> fetchResultsArray, | ||
SearchHits hits, | ||
int currentOffset, |
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.
No need to escape the hits from the caller just to get their length, adjusting this to make things more obviously safe in the only callsite.
Remove ref-counting that is obviously redundant because of clear
ownership transfers from
SearchHits
.This makes the compiler's life a little easier (i.e. saves cache and instructions) now and makes it easier to release
SearchHits
earlier than it is released today during response serialization.