Close the remaining native Array performance gaps (#505) - #540
Merged
Conversation
This was referenced Aug 17, 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.
What
Fixes the remaining #505 items at the layer that owns each cost: fancy (integer-list) reads, boolean mask reads,
array(list)construction, andastypewidening.flatten()andf64->f32were profiled, found already at NumPy speed on this host, and left untouched with tightened guards.Performance (release build, 1e6 elements, best-of-5, PECOS/NumPy ratio)
array(int_list)array(float_list)astypeu8->i64flatten()1000x1000Root causes (per-item
perfprofiles in the implementation report): per-element Python protocol dispatch during index/list parsing, per-element coordinate-vector allocation in selection, and a redundant full validation scan before provably-safe widening casts. Fixes: single-pass native index normalization, logical C-order offset gathering, native mask compaction, preallocated typed buffers for homogeneous built-in lists, and a range-subset bypass (source integer rangecontained intarget integer range, computed in i128) that skips validation only when overflow is impossible -- narrowing still validates (300 -> uint8still raises naming the value).Guard ceilings tightened, never loosened
test_performance_guard.pyceilings drop to ~10x the new medians (fancy 200ms->20ms, mask 300ms->50ms), with new guards for both list constructors andf64->f32; 15/15 pass on release.Verification (independent of the implementation run)
cargo clippy -p pecos-rslib --all-targets -- -D warnings,cargo fmt --check, unshieldedpre-commit run --all-files: clean.Implementation by Codex from a profile-first task packet; root causes, semantics, and benchmarks independently verified.