Add missing @propagate_inbounds and optimized form of setindex#2488
Merged
dennisYatunin merged 1 commit intomainfrom Apr 10, 2026
Merged
Add missing @propagate_inbounds and optimized form of setindex#2488dennisYatunin merged 1 commit intomainfrom
@propagate_inbounds and optimized form of setindex#2488dennisYatunin merged 1 commit intomainfrom
Conversation
imreddyTeja
approved these changes
Apr 9, 2026
Member
imreddyTeja
left a comment
There was a problem hiding this comment.
Do you have evidence that these changes make inbounds propagate as expected? Same question for the inlining of the index
ph-kev
reviewed
Apr 10, 2026
6af98da to
f02c5c9
Compare
f02c5c9 to
24d9120
Compare
Member
Author
|
@imreddyTeja Here are screenshots of the "Analysis: Flamegraph Profile" job from ClimaCore's CI that illustrate the difference; the first screenshot is from the latest main branch, while the second screenshot is from this branch: |
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.


Purpose
This PR fixes two issues I discovered while working on #2417:
unrolled_mapin Group/unrolling #2413, several@propagate_inboundsannotations where accidentally dropped, since neitherunrolled_mapnor the anonymous functions passed to it were annotated with@propagate_inbounds. This has led to unnecessary bounds checking during certain broadcast operations, which can be seen in the CI flame graphs for ClimaCore and ClimaAtmos.Base.setindex, including the performance-criticalstruct_field_viewandstruct_indices. It turns out thatBase.setindexdoes not always inline the index value, leading to unnecessary index comparisons and bounds checks during runtime. These were also visible in the CI flame graphs, though they were not as significant as the first issue.Content
Three new functions are added to a sub-module of
Utilities:unrolled_setindex,unrolled_insert, andunrolled_map_with_inbounds. These will eventually be generalized and moved toUnrolledUtilities.jl, but for now they can be explicitly imported fromClimaCore.Utilities.Unrolled. I expect we'll need to define other similar functions in the process of refactoringDataLayouts/Operators, after which we can update theUnrolledUtilitiesAPI to include them.