Skip to content

perf: reduce runtime overhead and memory usage - #79

Merged
owenthcarey merged 7 commits into
mainfrom
perf/speed-up-json-and-strings
Sep 13, 2026
Merged

owenthcarey merged 7 commits into
mainfrom
perf/speed-up-json-and-strings

Conversation

@owenthcarey

@owenthcarey owenthcarey commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This PR reduces runtime allocation, copying, and dispatch overhead across JSON, strings, collections, datetime, serialization, and native/JIT calls. It also adds regression coverage and keeps generated research artifacts out of the source tree.

Changes

  • Decode and encode JSON with fewer intermediate buffers; avoid whole-input string scans for bounded prefix/suffix checks and splitting.
  • Add native fast paths for deque operations, datetime arithmetic and formatting, numeric reductions, range collection, and supported pickle values, with guarded fallback paths.
  • Reduce Object and DictKey from 24 to 16 bytes on ARM64 through shared value storage. Use lazy instance metadata, compact slots, shared slot names, and reusable collector scratch space.
  • Improve JIT constants, scalar calls/results, list iteration/construction, native entry, and exception exits. Bound retained native-call scratch capacity while preserving callback, deoptimization, weak-reference, and C API lifetimes.
  • Add differential probes and regression tests, remove generated logs/results/source snapshots from the final tree, and enforce repository artifact rules in CI.
  • Fix Windows compilation after the storage refactor by sharing lazy DLL-directory instance dictionaries and gating a Unix-only import.

Measured improvements

These are recorded macOS ARM64 measurements against each change's own predecessor, not a fresh comparison of the final PR against main. Results from different stages must not be multiplied into a cumulative speedup.

Workload or change Recorded improvement
JSON roundtrip 73.0% less JIT workload time; 72.8% less interpreter workload time
JSON record encoding / decoding 4.07x / 3.53x faster
JSON numeric-array decoding 11.85x faster
Large ASCII / Unicode JSON decoding 88.4% / 61.1% lower peak RSS
Deque fixture 35.8% less workload time, 34.8% less process CPU time, 5.2% lower peak RSS
Datetime fixture 47.6% less workload time, 47.1% less process CPU time, 19.1% lower peak RSS
Shared value storage 2.34% lower geometric-mean peak RSS across 24 processes; every process improved
Public time.isoformat About 37% to 39% less execution time

The initial JSON pass reduced the 23-workload suite's geometric-mean workload time by 6%. The subsequent deque/datetime pass reduced JIT workload time by another 5.3% against its immediate predecessor. The JSON report, deque/datetime report, and runtime report document methods, tradeoffs, and reproduction commands.

Limits: WeavePy does not yet outperform CPython across all workloads or metrics. Some short allocations, calls, fallback paths, and startup measurements regressed. The final scratch-capacity limit has no qualified timing samples. Later archived JIT/datetime experiments are not part of the active implementation and their gains are not claimed here.

Validation

  • The recorded runtime checkpoint passed 353 VM tests, 156 C API tests, 99 targeted checks, 44 independent CPython result checks, and 275 compatibility checks, plus formatting, strict lint, and no-JIT checks.
  • The Windows CI fix passes local formatting, the repository artifact check, all 11 repository-tool tests, whitespace validation, and a Windows GNU cross-check of the VM and its tests with all features and Rust warnings denied. The Windows CI log confirms that the DLL-directory creation, closing, and context-manager regression passes.
  • CI for the updated sources passed all 28 jobs for 9a10bae5, including platform tests, bundled and free-threaded regressions, distribution checks, benchmark gates, and all nine ecosystem shards.

Generated benchmark evidence remains available locally and in checkpoint history. Required Unicode/codec data, vendored build inputs, CI baselines, reusable tools, and regression fixtures remain tracked.

Reduce allocation and dispatch overhead in runtime and code metadata,
JIT execution, collections, numeric operations, pickle, and datetime.
Add regression coverage and retain compact benchmark reports and samples.
Keep repeated source snapshots, caches, and bulk profiles in local archives.

This is an ongoing-work checkpoint. The latest weakref comparison remains
provisional, and allocation profiles, startup controls, and a fresh full
census are still pending. CPython continues to lead many metrics.

Validation: workspace formatting and all-target/all-feature Clippy pass;
729 workspace tests pass; documentation tests pass with one ignored case.
The 275 configured compatibility checks, 42 focused release checks, and
114 performance-fixture checks also pass. Preserve the initial sandboxed
socket-test failure alongside the successful full outside-sandbox run.
@owenthcarey owenthcarey changed the title perf: speed up JSON and string operations perf: reduce runtime overhead and memory usage Sep 13, 2026
@owenthcarey
owenthcarey merged commit 1fccda2 into main Sep 13, 2026
28 checks passed
@owenthcarey
owenthcarey deleted the perf/speed-up-json-and-strings branch September 13, 2026 21:20
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