Cache frozen FieldType to skip schema validation#15886
Merged
ChrisHegarty merged 16 commits intoapache:mainfrom Apr 7, 2026
Merged
Cache frozen FieldType to skip schema validation#15886ChrisHegarty merged 16 commits intoapache:mainfrom
ChrisHegarty merged 16 commits intoapache:mainfrom
Conversation
Contributor
Author
Contributor
|
This looks goo to me Tim. Can we add a change log entry for 10.5? |
Contributor
Author
Done. |
benwtrent
reviewed
Mar 30, 2026
ChrisHegarty
pushed a commit
that referenced
this pull request
Apr 7, 2026
When indexing, every field in every document has its schema built via updateDocFieldSchema and validated via assertSameSchema against the existing FieldInfo. For the common case where a field consistently uses the same frozen FieldType instance, this work is redundant — a frozen type is immutable, so its schema contribution is identical every time. This change caches the frozen FieldType on each PerField and checks same object instance to detect when the type hasn't changed. When it matches, schema building and validation are skipped entirely, and FieldSchema only resets its docID. If a different type is encountered, the cache is invalidated and the full validation path runs. A deoptimize path handles multi-valued fields where a later value uses a different type than earlier values within the same document. Adds FieldType.isFrozen() to support the optimization, and new tests covering the fast-path, cache invalidation, deoptimize, cross-segment validation, and document blocks.
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.


When indexing, every field in every document has its schema built via
updateDocFieldSchema and validated via assertSameSchema against the
existing FieldInfo. For the common case where a field consistently uses
the same frozen FieldType instance, this work is redundant — a frozen
type is immutable, so its schema contribution is identical every time.
This change caches the frozen FieldType on each PerField and checks
same object instance to detect when the type hasn't changed. When it
matches, schema building and validation are skipped entirely, and
FieldSchema only resets its docID. If a different type is encountered,
the cache is invalidated and the full validation path runs. A
deoptimize path handles multi-valued fields where a later value uses a
different type than earlier values within the same document.
Adds FieldType.isFrozen() to support the optimization, and new tests
covering the fast-path, cache invalidation, deoptimize, cross-segment
validation, and document blocks.