Skip to content

feat: q2 filter change + parallelized gridding for stats - #16

Merged
pranav-walimbe merged 3 commits into
mainfrom
feat/fast-sampler
Aug 25, 2026
Merged

feat: q2 filter change + parallelized gridding for stats#16
pranav-walimbe merged 3 commits into
mainfrom
feat/fast-sampler

Conversation

@pranav-walimbe

Copy link
Copy Markdown
Owner

No description provided.

@pranav-walimbe
pranav-walimbe force-pushed the feat/fast-sampler branch 3 times, most recently from 857873b to 7d9dff3 Compare August 25, 2026 02:17
collect_points made two serial passes over every point. estimate_distribution scattered
into a sqrt(n) cell grid, which is n cells and so 12 MB at SF1 and 120 MB at SF10, then
build_histogram scattered again into 32x32.

Both now come from one parallel pass over a fixed 256x256 grid. At 256 KiB it stays in
cache and is cheap enough to hold per thread, so the fill is a rayon fold and reduce with
no atomics. Folding blocks of 8 gives the histogram exactly, since flooring at 256 then
dividing by 8 lands on the same cell as flooring at 32.

Distribution now uses Morisita's index of dispersion rather than a coefficient of
variation. The old test needed a sqrt(n) grid to pin mean occupancy at 1.0, because raw
CV depends on how crowded a cell is. Morisita's index reads 1.0 for a Poisson field at
any grid size or point count, which is what frees the grid to be fixed and small.

Statistics on real pickup points, best of 7:

  points        before     after   delta
  100,000       0.0006    0.0006   -5.9%
  1,000,000     0.0061    0.0021  -66.5%
  3,000,000     0.0224    0.0039  -82.7%

The histogram drives early exits that return an empty result, so a cell that wrongly
reads empty is a wrong answer and not a slow one. A differential run of 1000 queries over
3M real points, 515 of them landing in empty space, returns identical answers on both
builds, and folded_histogram_matches_direct_binning holds the exactness in a test.
q2 scanned z_name and z_boundary for every zone, collected them, then filtered to
Coconino County in Python and kept one row. The pinned reference SQL already puts
the filter inside the subquery, so pushing it into scan_parquet matches the query
rather than diverging from it.

Polars prefilters, reading the predicate column and decoding z_boundary only for
surviving rows. Measured on a fixture built to SF1's zone layout, six files of one
row group each: 0.512s to 0.155s and a 2273 MiB peak to 1275 MiB, so -70% wall and
-44% peak.
…ause

53 comments across the codebase followed the shape 'fact, so consequence' or 'fact,
which explains it'. The clause after the comma restated what the code already showed
or padded a claim the reader did not need.

Each one now states its fact and stops. Where the trailing clause carried real
information it moves into the sentence or onto its own line rather than hanging off a
comma.

Comments only. No code changed.
@pranav-walimbe
pranav-walimbe merged commit 8e0729f into main Aug 25, 2026
2 checks passed
@pranav-walimbe
pranav-walimbe deleted the feat/fast-sampler branch August 25, 2026 02:31
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