Cache frozen FieldType to skip schema validation (#15886)

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.
4 files changed
tree: 6c9862ff724c4f500e922bde71e5a3646b682bd1
  1. .devcontainer/
  2. .github/
  3. .idea/
  4. .vscode/
  5. build-tools/
  6. dev-docs/
  7. dev-tools/
  8. gradle/
  9. help/
  10. lucene/
  11. .asf.yaml
  12. .dir-locals.el
  13. .editorconfig
  14. .git-blame-ignore-revs
  15. .gitattributes
  16. .gitignore
  17. .lift.toml
  18. .pre-commit-config.yml
  19. .rumdl.toml
  20. build-options.properties
  21. build.gradle
  22. CONTRIBUTING.md
  23. gradlew
  24. gradlew.bat
  25. LICENSE.txt
  26. NOTICE.txt
  27. README.md
  28. settings.gradle
  29. versions.lock
README.md

Apache Lucene

Lucene Logo

Apache Lucene is a high-performance, full-featured text search engine library written in Java.

Build Status Revved up by Develocity

Online Documentation

This README file only contains basic setup instructions. For more comprehensive documentation, visit:

Building

Basic steps

  1. Install JDK 25 using your package manager or download manually from OpenJDK, Adoptium, Azul, Oracle or any other JDK provider.
  2. Clone Lucene's git repository (or download the source distribution).
  3. Run gradle launcher script (gradlew).

We‘ll assume that you know how to get and set up the JDK - if you don’t, then we suggest starting at https://jdk.java.net/ and learning more about Java, before returning to this README.

Contributing

Bug fixes, improvements and new features are always welcome! Please review the Contributing to Lucene Guide for information on contributing.

  • Additional Developer Documentation: dev-docs/

Discussion and Support