Skip to content

[python] Cache decoded BLOB indexes - #9547

Open
YannByron wants to merge 1 commit into
apache:masterfrom
YannByron:perf/python-blob-index-cache
Open

[python] Cache decoded BLOB indexes#9547
YannByron wants to merge 1 commit into
apache:masterfrom
YannByron:perf/python-blob-index-cache

Conversation

@YannByron

Copy link
Copy Markdown
Contributor

Purpose

Creating a FormatBlobReader currently decompresses the same immutable BLOB index and rebuilds all offsets every time. Workloads that repeatedly open the same BLOB files pay this CPU cost on each reader creation.

Cache decoded indexes by their exact compressed bytes with a bounded 16-entry LRU. Cached values remain immutable, while every reader receives its own mutable lists. This change is extracted from #9466 so the generic reader optimization can be reviewed independently.

A local paired ACT benchmark on an Apple M2 Pro showed Paimon batch-fetch throughput improving from 148.70 to 172.56 samples/s (+16.05%). With the same HDF5 baseline, the Paimon/HDF5 ratio improved from 87.88% to 101.98%; tensor fingerprints and three rounds of train/validation loss remained identical.

Tests

  • PYTHONPATH=. python -m pytest pypaimon/tests/blob_test.py -q (118 passed, 1 skipped)
  • ruff check pypaimon/read/reader/format_blob_reader.py pypaimon/tests/blob_test.py
  • flake8 --config=dev/cfg.ini pypaimon/read/reader/format_blob_reader.py pypaimon/tests/blob_test.py
  • git diff --check origin/master..HEAD

self.blob_lengths = blob_lengths
self.blob_offsets = blob_offsets
# Readers own mutable lists; the cached immutable index is shared.
blob_lengths, blob_offsets = _decode_blob_index(index_bytes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use file_path as the cache key. Paimon BLOB files are immutable and have unique paths, so the path already identifies the index. Keying the cache by index_bytes forces every reader to read the complete index before it can check the cache, hashes and compares a potentially large byte string, and retains the compressed bytes alongside the decoded tuples. A path-keyed cache can avoid all of these costs.

Cache immutable decoded indexes by BLOB file path so repeated readers skip index I/O and offset reconstruction.

Co-Authored-By: Codex <noreply@anthropic.com>
AI-Model: gpt-5.6-sol
AI-Contributed/Feature: 45/45
AI-Contributed/UT: 47/47
@YannByron
YannByron force-pushed the perf/python-blob-index-cache branch from 922acfc to 4103c3b Compare September 2, 2026 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants