Skip to content

Conversation

nsajko
Copy link
Member

@nsajko nsajko commented Sep 12, 2025

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.

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.
Copy link
Collaborator

@mateuszbaran mateuszbaran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks reasonable.

@nsajko
Copy link
Member Author

nsajko commented Sep 14, 2025

Merge?

@mateuszbaran mateuszbaran merged commit a9333fa into JuliaArrays:master Sep 14, 2025
17 of 24 checks passed
@nsajko nsajko deleted the colon_specialization branch September 14, 2025 14:36
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.

2 participants