force specialization of dims argument type where it may be Colon#1318
Merged
mateuszbaran merged 1 commit intoJuliaArrays:masterfrom Sep 14, 2025
nsajko:colon_specialization
Merged
force specialization of dims argument type where it may be Colon#1318mateuszbaran merged 1 commit intoJuliaArrays:masterfrom nsajko:colon_specialization
Colon#1318mateuszbaran merged 1 commit intoJuliaArrays:masterfrom
nsajko:colon_specialization
Conversation
As discussed in the Performance Tips in the Manual, Julia avoids specializing calls on the type of `Function` arguments by default. The function `:`, `(:) isa Function`, is often used not as a callable, but as the special value for specifying the "full range" or "all dimensions". However in such cases we often forget to force specialization on the type of `:`. This change fixes that. See PR JuliaLang/julia#59474, which applies the same kind of change in Julia itself. NB: I don't have an example where this change helps for StaticArrays, however the eliminated invalidation in the linked JuliaLang/julia PR is proof that it does help in some cases. Finding such examples is difficult because the compiler is often able to achieve good results because of constant propagation. However constprop is often fragile, so it is better to avoid relying on it. For example, constprop through recursion is not even attempted by the Julia compiler. I believe this change should not cause any real-world compile time regression, as `:` is the only function that is valid as a dims argument.
mateuszbaran
approved these changes
Sep 12, 2025
Collaborator
mateuszbaran
left a comment
There was a problem hiding this comment.
Thanks, this looks reasonable.
Member
Author
|
Merge? |
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.
As discussed in the Performance Tips in the Manual, Julia avoids specializing calls on the type of
Functionarguments by default.The function
:,(:) isa Function, is often used not as a callable, but as the special value for specifying the "full range" or "all dimensions". However in such cases we often forget to force specialization on the type of:. This change fixes that.See PR JuliaLang/julia#59474, which applies the same kind of change in Julia itself.
NB: I don't have an example where this change helps for StaticArrays, however the eliminated invalidation in the linked JuliaLang/julia PR is proof that it does help in some cases. Finding such examples is difficult because the compiler is often able to achieve good results because of constant propagation. However constprop is often fragile, so it is better to avoid relying on it. For example, constprop through recursion is not even attempted by the Julia compiler.
I believe this change should not cause any real-world compile time regression, as
:is the only function that is valid as a dims argument.