Skip to content

perf(python): compile row decoders and batch uniform prefixes - #96

Merged
eliahilse merged 6 commits into
mainfrom
perf/python-decode
Oct 21, 2026
Merged

eliahilse merged 6 commits into
mainfrom
perf/python-decode

Conversation

@eliahilse

@eliahilse eliahilse commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

What

Faster Python decoding with no behaviour change. Pure Python, no new dependencies, Python 3.10 to 3.14.

  • Compiled row decoders: each IR node gets a specialised reader at compile time instead of dispatching on every value. Metadata is cached, and floats are read directly.
  • Batching: runs of uniform-prefix values are batched, and one- and two-byte varints take a fast path. The batching is guarded so the first failure and its error code stay exactly as before (wire-v0 §6 and §9).
  • Encoding is untouched: same code, same call counts.

Bulk byte charging for rows and a full-array float preflight were considered and rejected, because they would change which failure is reported first.

Performance

Median wall-clock ms of 31 alternating runs, 10k rows, against main (22cf2a9), on Python 3.13. The benchmark is python/benchmarks/decode_bench.py; results and how to reproduce them are in python/benchmarks/README.md.

case decode main decode this PR speedup
mixed row 151.7 59.7 2.54×
nested row 306.7 158.6 1.93×
mixed columnar 22.0 18.9 1.16×
nested columnar 62.0 49.7 1.25×
packed strings 8.7 5.8 1.50×
grammar/derived 4.3 3.7 1.19×

Encode times are within noise (largest increase 1.8%).

Tests

  • New test_decode_specialization.py covers the compiled readers and batch edges, including empty batches.
  • The full suite passes (4,940 tests, Hypothesis and fuzz included) under strict mypy.
  • Cross-language differential (TS, Python, Rust), seeds 1 and 2: 0 divergences on vector replay, compile, encode, decode, re-encode, round trip and JSON fallback. The only flag is the known packed-limit case, which depends on the deflate output. Interop passes.
  • The sdist now leaves out benchmarks/ and any local .hypothesis/ data (a45a6cb). Built and listed: the wheel holds only the package, and the sdist holds the package plus README, CHANGELOG, LICENSE and NOTICE.

Review (cross-family)

  • Muse: no behaviour divergence in about 430k paired cases against main, covering decoded values and types, the first error, error codes, paths and limit accounting. Its one P2, benchmarks shipping in the sdist, is fixed in a45a6cb.
  • Claude: no findings in 247k paired cases. These covered random schemas on both plans with profiles, every truncation, byte mutations, 11 tight-limit sets, targeted cases on both batching fast paths, and Python 3.10 (compiled and smoke-tested on CPython 3.10.20).

🤖 Generated with Claude Code

eliahilse and others added 6 commits October 21, 2026 18:16
Co-Authored-By: GPT 6.1 Sol <noreply@openai.com>
Co-Authored-By: GPT 6.1 Sol <noreply@openai.com>
Co-Authored-By: GPT 6.1 Sol <noreply@openai.com>
Co-Authored-By: GPT 6.1 Sol <noreply@openai.com>
Co-Authored-By: GPT 6.1 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eliahilse
eliahilse merged commit 0093656 into main Oct 21, 2026
17 checks passed
@eliahilse
eliahilse deleted the perf/python-decode branch October 21, 2026 18:02
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.

1 participant