Skip to content

Specialize ∇getindex! on the indices - #876

Merged
devmotion merged 2 commits into
mainfrom
dmw/getindex-vararg
Nov 20, 2026
Merged

devmotion merged 2 commits into
mainfrom
dmw/getindex-vararg

Conversation

@devmotion

Copy link
Copy Markdown
Member

Julia doesn't specialize on Vararg arguments that are only passed through to another function (performance tips). As a result, the broadcasting ∇getindex! methods allocate on every call. These methods are used by unthunk and add! of the getindex/view cotangents. Writing inds::Vararg{Any,N}) where {N} forces specialization.

Example: accumulating a 100-element column, ∇getindex!(dx, dy, Base.Slice(Base.OneTo(100)), 7)

time allocations
main 190 ns 6 (208 B)
this PR 16 ns 0

The PR adds a test that checks ∇getindex! doesn't allocate. It is independent of #875; whichever PR is merged second only needs a version bump.

🤖 Generated with Claude Code

devmotion and others added 2 commits November 20, 2026 09:11
Julia does not specialize on `inds...` that are only passed through, so the
broadcasting `∇getindex!` methods allocated on every call (6 allocations and
~190 ns instead of 0 allocations and ~16 ns for a 100-element column).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.65%. Comparing base (fe88a64) to head (3778227).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #876   +/-   ##
=======================================
  Coverage   96.65%   96.65%           
=======================================
  Files          28       28           
  Lines        3615     3615           
=======================================
  Hits         3494     3494           
  Misses        121      121           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@devmotion
devmotion merged commit 98dc481 into main Nov 20, 2026
11 checks passed
@devmotion
devmotion deleted the dmw/getindex-vararg branch November 20, 2026 08:57
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