-
Notifications
You must be signed in to change notification settings - Fork 25.4k
Optimize IngestDocument FieldPath allocation #120573
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pinging @elastic/es-data-management (Team:Data Management) |
Hi @joegallo, I've created a changelog YAML for you. |
nielsbauman
reviewed
Jan 22, 2025
nielsbauman
approved these changes
Jan 22, 2025
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.
LGTM, thanks! 🚀
joegallo
added a commit
to joegallo/elasticsearch
that referenced
this pull request
Jan 29, 2025
💚 Backport successful
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
auto-backport
Automatically create backport pull requests when merged
:Data Management/Ingest Node
Execution or management of Ingest Pipelines including GeoIP
>enhancement
Team:Data Management
Meta label for data/management team
v8.18.0
v9.0.0
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.
Constructing a
FieldPath
from aString path
requires that we split (viaString#split
) into an array of substrings (we're splitting on dots, so for example"foo.bar.baz"
becomes["foo", "bar", "baz"]
).So that's allocation of an ArrayList to hold the results as we do the scan, allocation of the Strings to hold each individual substring, and finally allocation of the resulting array at the end when the scan is finished. It's not the slowest thing ever, but it's not free. Of course the scan itself has some small CPU cost, too. (For the record, though, we go down the fast path of
String#split
, so it's not like we're doing regexes here, thank goodness.)We call it like it's free, however (😬). Consider the happy path of a
rename
processor:elasticsearch/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/RenameProcessor.java
Lines 83 to 86 in 5efe216
Let's imagine we loop over 1000 incoming json documents and run that processor. For each json document we'll turn some path into a
FieldPath
twice (once for thegetFieldValue
and once for theremoveField
), then we'll turn some other path into aFieldPath
once (for thesetFieldValue
). And we do that for all 1000 documents.Anyway... that's a lot of arrays of substrings that we're allocating.
This PR introduces a local static cache that holds onto previously allocated
FieldPath
objects and allows us to look them up by the path they represent. Returning references to already allocatedFieldPath
objects is way faster than allocating new ones.The same pattern of a map that we just whack when it exceeds its size limit is applied in
StringLiteralDeduplicator
(introduced in #76405) andDateProcessor
(see #92880) -- it works pretty well!Like #120571 this doesn't improve any one ingest processor specifically, it just kinda makes them all a bit faster -- reading and writing values is what this makes faster, and most of what every processor does is read a value, do something with it, and then write the result.
This makes all of ingest on my local test benchmark faster by about 20%, but that's not necessarily indicative of normal workloads. It makes an example
convert
processor faster by 80%, and aremove
processor faster by 70%, but adate
processor only gets a smidge faster -- the former processors are mostly just shuffling values around, so the effect is outsized there, while the latter has real work to do (parsing date strings) that this doesn't make any faster.