Skip to content

Reduce Python formatting allocations and enforce Ruff/Pyright checks - #33

Merged
egorsmkv merged 2 commits into
masterfrom
perf/reduce-allocations
Oct 7, 2026
Merged

egorsmkv merged 2 commits into
masterfrom
perf/reduce-allocations

Conversation

@egorsmkv

@egorsmkv egorsmkv commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Python str()/repr() currently build an intermediate Rust String before constructing Unicode. Replace all 14 methods with checked stack-buffer formatting and direct PyString returns while preserving textual output. Rust parsing/arithmetic already use borrowed inputs and inline Copy values; a counting-allocator regression test guards these paths. Python output objects still allocate and copy bytes.

Add pinned Ruff 0.16.10 and Pyright 1.1.414 development tools, project configuration targeting Python 3.10, and a dedicated CI job for linting, formatting and type checking all Python source and stubs. Format examples, tests, benchmark and stubs; replace wildcard exports with explicit re-exports. Put native extension declarations in fasttime.pyi and add the comparison operators already supported at runtime. Only missing native implementation-source diagnostics are disabled; missing-import checks remain enabled.

Fix the unix_timestamps example's unsupported DateTime width formatting by using !s and run every example in the Python CI matrix.

Validation:

  • Ruff check and format --check passed for all 11 Python/stub files.
  • Pyright: 0 errors, 0 warnings.
  • Built and installed a release CPython 3.12 wheel; 38 Python tests and all five examples passed; benchmark runs successfully.
  • Rust tests passed with and without default features (20 tests each); allocation regression measured 0 Rust heap allocations on covered paths; clippy and cargo fmt passed.
  • Combined revision 5160673: Test CI passed (Ruff/Pyright, Rust, Python 3.10–3.14 tests and examples); Windows wheel CI passed all eight Windows jobs, including 3.14t/3.15t.

Local release-wheel formatting microbenchmarks on CPython 3.12/Linux favored stack formatting in both execution orders (~8–33% lower latency across measured cases); shared-host timings vary. Reproduce with python/benchmarks/string_formatting.py.

@egorsmkv egorsmkv changed the title perf: remove Rust heap allocations from Python str and repr Reduce Python formatting allocations and enforce Ruff/Pyright checks Oct 7, 2026
@egorsmkv
egorsmkv merged commit 20315e7 into master Oct 7, 2026
21 checks passed
@egorsmkv
egorsmkv deleted the perf/reduce-allocations branch October 7, 2026 20:43
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