Skip to content

perf(history): batch validation of reconstructed book levels - #16

Open
FlavioMili wants to merge 2 commits into
Synpath-ai:mainfrom
FlavioMili:perf/order-book-replay
Open

FlavioMili wants to merge 2 commits into
Synpath-ai:mainfrom
FlavioMili:perf/order-book-replay

Conversation

@FlavioMili

@FlavioMili FlavioMili commented Oct 9, 2026 •

Copy link
Copy Markdown

Historical reconstruction calls a Python OrderLevel constructor for every level of every emitted state. Pass level dictionaries into HistoricalOrderBook instead so its nested validator constructs the same validated models together. Decimal updates, ordering, metadata and independent output objects stay unchanged.

The diff contains only the example change, regression tests, and one standalone benchmark. Generated investigation artifacts are excluded.

Three alternating pairs on synthetic books with 100 levels per side measured 23% less reconstruction time and 15% less time including JSON encoding (Python 3.13.5, Pydantic 2.14.0, Ryzen AI 7 350, CPU 0). Candidate/control ratios were 0.768 [0.762–0.771] and 0.855 [0.847–0.866], respectively; corresponding A/A ranges were [0.997–1.024] and [0.996–1.052]. A separate tracemalloc diagnostic measured about 37 KB more temporary peak memory at depth 100. These results concern client reconstruction, not network downloads or the hosted service; the Texas Senate dataset was not measured.

Reproduce with identical parameters for both sources, alternating order across seeds 1729, 2738 and 3747:

git show 53af00c49b184d8ae5c3a4e0755fc98b26c25694:examples/track_historical_book.py > /tmp/history-control.py
python benchmarks/history_replay.py --replay-source /tmp/history-control.py --depth 100 --repeats 3 --seed 1729 --export
python benchmarks/history_replay.py --depth 100 --repeats 3 --seed 1729 --export

Omit --export to isolate reconstruction. Use --response recorded-range.json for a saved real API response. Measurements include response validation and full reconstruction after each delta; they exclude network and disk I/O.

Validation: 10 historical tests pass, including output and JSON equality against the previous construction across depths 0–1000, deletion/reinsertion and output independence.

@FlavioMili
FlavioMili marked this pull request as ready for review October 9, 2026 20:48

This branch has not been deployed

No deployments
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