shrink the binding for optimized clean builds - #64
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
saidctb
force-pushed
the
devel-build-time
branch
2 times, most recently
from
August 28, 2026 22:41
84742d1 to
2173030
Compare
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
force-pushed
the
devel-build-time
branch
from
August 29, 2026 00:30
2173030 to
9347ebc
Compare
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.
No description provided.