feat: opt-in multithreaded fill for synthetic data generators - #35
Merged
Conversation
Contributor
The synthetic generators are dominated by single-threaded numpy standard_normal draws (~0.9 GB/s), leaving cores idle. Add an opt-in n_workers parameter to scan_synthetic_regression and scan_synthetic_panel that fills the x/eps Gaussian draws in parallel. Draws are generated in fixed-size blocks (n_workers * fetch_size rows), each split across worker threads that fill disjoint slices in place via out=. standard_normal releases the GIL, so the fill scales across cores (~3x for regression, universe-dependent for panels). Reproducibility is re-keyed to (seed, n_workers, fetch_size) and stays independent of the batch_size Polars picks, so is_pure remains sound. n_workers=1 (default) keeps the exact serial path and its byte-for-byte output. Per-worker seed sub-streams are spawned lazily per block to keep seed storage at O(n_workers) and preserve bounded, streaming memory. Signed-off-by: Pascal Tomecek <40371786+ptomecek@users.noreply.github.com>
ptomecek
force-pushed
the
feat/threaded-synthetic-gen
branch
from
September 1, 2026 15:32
a171e17 to
76dc72e
Compare
ptomecek
marked this pull request as ready for review
September 1, 2026 15:51
hintse
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The synthetic data generators (
scan_synthetic_regression,scan_synthetic_panel) are dominated by single-threaded numpystandard_normaldraws (~0.9 GB/s), leaving cores idle — 10–70× slower than a parquet read on the same data. This adds an opt-inn_workersparameter that fills thex/epsGaussian draws in parallel.Approach
n_workers * fetch_sizerows), each split across worker threads that fill disjoint slices in place via numpy'sout=.standard_normalreleases the GIL, so the fill scales across cores.n_workers=1(default) is byte-for-byte identical to the previous serial path — the change is purely additive.(seed, n_workers, fetch_size)and stays independent of thebatch_sizePolars picks, sois_pureremains sound.O(n_workers)and preserving bounded, streaming memory.Measured throughput (32 cores)
Speedup for the regression path is Amdahl-bound by the serial DataFrame build; panels benefit proportionally to
n_symbols(the per-date batch size).Tests
n_workers=1byte-parity with the serial path; determinism per(seed, n_workers).batch_sizeindependence (in-memory vs streaming engine), incl. a full panel case withcategories+group_by+use_weights.take()chunking-invariance (the highest-risk logic).Full
io_sourcessuite green;ruff check+ruff format --checkclean.