Skip to content

shrink the binding for optimized clean builds - #64

Merged
saidctb merged 1 commit into
mainfrom
devel-build-time
Aug 29, 2026
Merged

shrink the binding for optimized clean builds#64
saidctb merged 1 commit into
mainfrom
devel-build-time

Conversation

@saidctb

@saidctb saidctb commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.76923% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
prik/codegen/c/binding.py 80.76% 5 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

@saidctb
saidctb force-pushed the devel-build-time branch 2 times, most recently from 84742d1 to 2173030 Compare August 28, 2026 22:41
Building a large project with optimizing compiler flags spent most of its
time compiling the generated C binding. Every ordinary array argument emitted
the whole sequence inline -- validate the ndarray, check each declared extent,
take the data pointer, fold the trailing axes, and on the other branch build
an expected-shape tuple for the native-handle handoff. The logic is identical
at every site; only the dtype, rank, layout, extents, and names differ. The
reference BLAS repeated it 200 times, so the compiler optimized the same
shape 200 times over.

A wrapper now passes those differing values to one prik_bind_array helper and
receives the pointer and extents back, so the logic is optimized once. Plans
that also carry runtime rank, itemsize, stride, upper-bound, or dense-actual
roles keep their own inline sequence, as do strings, front-flattened storage,
and any argument whose direct and handoff routes disagree on an axis.

Bindings are also no longer split across translation units. A project of 128
or more procedures previously generated <module>_wrapper_001.c and siblings so
those units could compile concurrently. Splitting never reduced the work: each
unit re-parsed Python.h and the NumPy headers, which measured as a 14% rise in
total compiler time, repaid only when cores sat idle. A project's own sources
rarely leave them idle, and on a four-core machine the split lost outright.
One file also leaves one file to read when inspecting generated output.

For the 155-source reference BLAS with -O3 -march=native, the binding emits a
third less code and its compile drops from 5.77s to 4.16s. A 150-procedure
project that did split goes from six units and 5.87s to one unit and 2.54s.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDeRuWHDwVLK8aeQARe3iT
@saidctb saidctb changed the title Shard and shrink the binding for optimized clean builds shrink the binding for optimized clean builds Aug 29, 2026
@saidctb
saidctb merged commit 412d884 into main Aug 29, 2026
14 checks passed
@saidctb
saidctb deleted the devel-build-time branch August 29, 2026 01:19
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