perf(avro): cache Avro-to-Iceberg schema conversion#3663
Open
vishnuprakaz wants to merge 1 commit into
Open
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
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
AvroFileHeader.get_schema()re-parses the embedded Avro schema and converts it to an Iceberg schema on every fileopen. All manifests in a table share the same schema, so during scan planning we redo that identical conversion
once per manifest for no reason.
Caching it (keyed on the schema string) means each distinct schema is converted only once.
I timed
scan().plan_files()on unpartitioned tables of a few sizes,mainvs this branch (median of 10 warm runs):Roughly 1.8x throughout, and since the wasted work is per-manifest, larger tables save more. Results are identical.
This is a narrow, unpartitioned table; a partitioned one has a wider manifest schema and would gain at least as
much.
Uses
functools.lru_cache, like the existing_cached_resolve_s3_regioninio/pyarrow.py, so no new dependency.Schemais immutable and already shared across scan threads, so sharing one cached instance is safe.Are these changes tested?
Yes. A unit test in
tests/avro/test_file.pychecks the cached schema is correct, that the same schema stringreturns the same object, and that a different string returns a different schema. There's also a benchmark in
tests/benchmark/test_avro_schema_cache_benchmark.py(run with-m benchmark) for the numbers above. Existingavro/table/manifest tests pass.
Are there any user-facing changes?
No, same behavior, just faster scan planning on tables with many manifests.