Skip to content

PERF: fast-path empty insert indices#31898

Draft
KRRT7 wants to merge 2 commits into
numpy:mainfrom
KRRT7:insert-empty-fastpath
Draft

PERF: fast-path empty insert indices#31898
KRRT7 wants to merge 2 commits into
numpy:mainfrom
KRRT7:insert-empty-fastpath

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

PR summary

Add a fast path for np.insert with empty integer insertion indices. The result is still a copy, and the path keeps the existing empty-assignment step so values validation behavior is preserved.

ASV quick comparison against main:

bench_function_base.Insert.time_empty_indices((100, 100), 0, list):     50.8 us -> 39.9 us
bench_function_base.Insert.time_empty_indices((100, 100), None, array): 45.4 us -> 24.7 us
bench_function_base.Insert.time_empty_indices((1000,), 0, list):        39.7 us -> 19.3 us
bench_function_base.Insert.time_empty_indices((1000,), 0, array):       37.2 us -> 17.4 us
bench_function_base.Insert.time_empty_indices((1000,), None, array):    37.5 us -> 17.0 us
bench_function_base.Insert.time_empty_indices((100, 100), None, list):  52.5 us -> 22.0 us
bench_function_base.Insert.time_empty_indices((100, 100), 0, array):    64.3 us -> 22.7 us
bench_function_base.Insert.time_empty_indices((1000,), None, list):     92.4 us -> 30.4 us

First time committer introduction

I am a NumPy user/contributor looking at small, focused performance improvements in common array operations. I will handle review discussion and follow-up changes directly.

AI Disclosure

LLM / Harness: hybrid.

AI assistance was used to inspect the codebase, run local commands and benchmarks, draft PR text, and help prepare candidate patches. I reviewed the generated suggestions, selected the final changes, and am responsible for the code, submission, and follow-up discussion. Some PR text and candidate code edits were drafted with AI assistance; the final patch and text were reviewed and edited by me.

@mattip

mattip commented Jul 7, 2026

Copy link
Copy Markdown
Member

You should also benchmark the non-empty insert for regressions

@KRRT7 KRRT7 marked this pull request as draft July 7, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants