Skip to content

Conversation

@original-brownbear
Copy link
Contributor

Flattening the stack a little for rewriting, we almost never go async on a rewrite so we can save some stack depth, unnecessary listener wrapping (and resulting retention of heap objects!) here and maybe subjectively make the code a little nicer to read.
A nice side-effect of this change is that it makes profiling much easier to interpret as far as the cost of query rewriting is concerned.

This should be relatively trivial to review, there's no expected behavior changes in this because I actively stayed away from removing callback-style code for ref-counted objects/SearchPhaseResult instances.

Flattening the stacks a little here where we close to never go async
and most importantly setting up bigger follow-ups.
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Mar 13, 2025
threadPool
);
final IndexShard shard = getShard(request);
rewriteAndFetchShardRequest(shard, request, listener.delegateFailure((l, rewritten) -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a bug that rewritten wasn't used in the old code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea but a trivial one funny enough since (for better or for worse ...) we mutate the object in-place. This doesn't change behavior but saves a little GC work by removing needless capturing :)

Copy link
Contributor

@benchaplin benchaplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay - had to take some more time to learn about rewriteAndFetch. LGTM!

@original-brownbear original-brownbear closed this by deleting the head repository Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch v8.19.0 v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants