Skip to content

Commit

Permalink
Slightly speed up scripts (backport of elastic#68478) (elastic#68524)
Browse files Browse the repository at this point in the history
This saves a couple of nanoseconds on ever invocation of a painless
script that uses `SearchLookup`. Which is most of the scripts in the hot
path. This amounts to a 3.5% performance savings for things like script
scoring and runtime fields. We got this by speeding up a method that the
async profiler reported as taking 20% of the time running a script score
with painless. This drops it to 1%. You'd think that'd result in a 19%
speed up. But no such luck.
  • Loading branch information
nik9000 authored Feb 4, 2021
1 parent 35e2de9 commit 95ee440
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ private FieldLookup loadFieldData(String name) {
}

private void clearCache() {
if (cachedFieldData.isEmpty()) {
/*
* This code is in the hot path for things like ScoreScript and
* runtime fields but the map is almost always empty. So we
* bail early then instead of building the entrySet.
*/
return;
}
for (Entry<String, FieldLookup> entry : cachedFieldData.entrySet()) {
entry.getValue().clear();
}
Expand Down

0 comments on commit 95ee440

Please sign in to comment.