Skip to content

Removal of @pure makes constant-prop less effective. #49472

@sloede

Description

@sloede

With the current commit on the backports-release-1.9 branch (29889c7), in StaticArrays.jl a type instability is triggered when running Julia with --check-bounds=no. I tried to create an MWE as follows:

Start Julia with

JULIA_DEPOT_PATH=$PWD/tmp-depot path/to/julia-1.9-29889c7a1c --project=. --check-bounds=no

for a clean depot. Then run the following code:

julia> using Pkg; Pkg.add(PackageSpec(name="StaticArrays", version=v"1.5.21"))

julia> using StaticArrays

julia> some_vec = SVector(1.0)
1-element SVector{1, Float64} with indices SOneTo(1):
 1.0

julia> foo(u) = SVector(u[1])
foo (generic function with 1 method)

julia> @code_warntype foo(some_vec)
MethodInstance for foo(::SVector{1, Float64})
  from foo(u) @ Main REPL[4]:1
Arguments
  #self#::Core.Const(foo)
  u::SVector{1, Float64}
Body::Any
1%1 = Base.getindex(u, 1)::Float64%2 = Main.SVector(%1)::Any
└──      return %2

When starting Julia without --check-bounds=no, the output of @code_warntype is as expected:

julia> @code_warntype foo(some_vec)
MethodInstance for foo(::SVector{1, Float64})
  from foo(u) @ Main REPL[4]:1
Arguments
  #self#::Core.Const(foo)
  u::SVector{1, Float64}
Body::SVector{1, Float64}
1%1 = Base.getindex(u, 1)::Float64%2 = Main.SVector(%1)::SVector{1, Float64}
└──      return %2

This causes a considerable performance regression to the point that code that heavily uses StaticArrays in hot loops becomes unusable.

cc @ranocha

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceMust go fasterregressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions