Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #138991
This is a bit of work-in-progress that I've developed on the way to an actual performance improvement -- these changes are mostly new tests, and little bits of tidying, but there are a couple of microoptimizations that I wanted to get out of the way. My primary goal here is to get this little bit of work off my machine, so I can focus on the remaining bit of work that'll actually get a us the real improvement. Ideally, by splitting this out, it'll be easier to review this relatively trivial part of the work separate from the 'real' follow up pull request.
5f51e5f fixes something that popped out at me on an allocation flamegraph for Document Level Security (DLS) -- since we re-compile the mustache template per query (at least currently), the allocation of a fresh string on each compilation in order to do a contains check seems a bit silly. The calling code is here:
elasticsearch/server/src/main/java/org/elasticsearch/script/ScriptService.java
Lines 621 to 623 in 97ee7fc
Which itself calls into:
https://github.com/elastic/elasticsearch/blob/main/server/src/main/java/org/elasticsearch/script/ScriptService.java#L662-L664
So the previous code was freshly allocating a new lowercased string on every script compilation, and then hashing that string (because it's freshly allocated, it wouldn't have a cached hashcode). So this saves the lowercasing, allocation, and hashing, since it's just be a static already-lowercased-String with a cached hashcode. It's a pretty tiny improvement, though, but it's not nothing.
97622ba and f525f70 are an optimization that shows up in the allocation profile for
setandappendprocessors, but I noticed it while looking for improvements in thedateprocessor (funnily enough). In the case of using a mustache template to look up the timezone to use for date parsing, we read a String and then render it, but in order to do that we end up going through an unhappyCollectionUtils.ensureNoSelfReferencescheck that allocates a freshCollections.newSetFromMap(new IdentityHashMap<>()). This optimizes that out by deferring the allocation until we actually need it.XContentBuilderhas its own similarensureNoSelfReferencesand that already does a lazy allocation of the identity set (albeit by a different means).