Repository navigation
Avro: Cache the Avro to Iceberg schema conversion per schema string - #4384
Open
zn-danielbariudin wants to merge 1 commit into
Open
zn-danielbariudin wants to merge 1 commit into
zn-danielbariudin wants to merge 1 commit into
Conversation
Author
|
@Fokko @kevinjqliu could you take a look when you have a moment? Small change for apache/iceberg-python#3662: it caches the Avro schema conversion, and plan_files() on 150 manifests goes from ~56 ms to ~30 ms. Thanks |
Contributor
|
I'm torn on this one. There is a reasonable speedup, but the tradeoff is on increased memory. Also, hashing the schema is not cheap. Can you maybe profile the memory? |
This branch has not been deployed
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.
Closes #3662
Rationale for this change
Every manifest in a table carries the same Avro schema string in its header, but
AvroFileHeader.get_schema()parsed and converted that string to an IcebergSchemaon every file open. During scan planning this repeats the same conversion once per manifest.This caches the conversion by schema string with
functools.lru_cache, so each distinct schema is converted once per process.Schemais a frozen model, so sharing the cached instance between readers is safe.lru_cachekeeps at most 128 schema strings; a process sees only a few distinct manifest schemas.Builds on #3663 by @vishnuprakaz (picked up with his 👍 on the issue); he is credited as co-author on the commit.
Benchmark
plan_files()on an unpartitioned table with 150 manifests (localSqlCatalog, 7 runs in one process), Python 3.14.7, Apple M5 Pro:plan_files()plan_files()medianplan_files()first callBenchmark script
Run with
uv run python bench_plan_files.py 150.Are these changes tested?
Yes. Added
test_get_schema_reuses_conversion_for_identical_schema_stringsintests/avro/test_file.py: it checks the converted schema, that two headers with the same schema string return the same instance, and that a different string returns a different one. The full unit suite passes locally.Are there any user-facing changes?
No API changes. Scan planning is faster on tables with many manifests.