Restore delegate caching in IdResolver - #8973
Merged
Merged
Conversation
`IdResolver.Resolve` builds a compiled getter delegate via `DynamicPropertyAccessor` and caches it so subsequent resolves of the same type avoid reflection. Commit 4117107 ("Add (experimental) native AOT support") kept the cache write on the failure path but dropped it on the success path, so the delegate was rebuilt for every call. In practice this means a full round of reflection (`GetProperty`, `MakeGenericMethod`, `MethodInfo.Invoke`, `CreateDelegate`) plus two closure allocations for every document whose id is inferred, which happens twice per document during bulk indexing (once in `BulkIndexOperation.SetValues` and again in `IdConverter.Write`). Measured over 100,000 resolves of the same type: ~64 ms and 55.2 MB allocated before, ~3.5 ms and 40 bytes after. Note the sibling `RoutingResolver`, rewritten in the same commit, caches on both the success and failure paths. Partially addresses elastic#7664.
Member
|
Hi @fresh55 , thanks for the PR! |
Contributor
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation and see the Github Action logs for details |
Contributor
Author
|
thanks for merging is the routingresolver half of #7664 still worth a pr or has that moved on. happy to open one if it is useful |
flobernd
pushed a commit
that referenced
this pull request
Aug 14, 2026
flobernd
pushed a commit
that referenced
this pull request
Aug 14, 2026
This was referenced Aug 28, 2026
Closed
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
IdResolver only caches the getter delegate when resolution fails. On success it
returns without caching, so the delegate is rebuilt on every call.
Dropped in 4117107 during the aot rework. RoutingResolver from the same
commit still caches both paths.
100k resolves of the same type: 64 ms / 55.2 MB before, 3.5 ms / 40 bytes after.
Partially addresses #7664. That issue also mentions closure allocations in
RoutingResolver which I left alone here, happy to do that in a separate pr.