Skip to content

Commit

Permalink
Slightly speed up scripts (elastic#68478)
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 committed Feb 4, 2021
1 parent bfdde77 commit 8f565ce
Showing 1 changed file with 8 additions and 0 deletions.
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 8f565ce

Please sign in to comment.