Skip to content

regression with getfield access on global objects #50870

@rfourquet

Description

@rfourquet

Compared to v1.8:

  • v1.9.2 has a regression where a.xx allocates (whereas getfield(a, :xx) doesn't)
  • v1.10.0-beta1 has a regression where both a[1].xx and getfield(a[1], :xx) allocate when a is a a tuple

The following script should show the problem:

using BenchmarkTools

struct XX
    xx::Vector{Int}
end

const XXs = XX(Int[])

get1() = length(getfield(XXs, :xx))
get2() = length(XXs.xx)

const YYs = (XX(Int[]),)

get3() = length(getfield(YYs[1], :xx))
get4() = length(YYs[1].xx)

@btime get1()
@btime get2()
@btime get3()
@btime get4()
nothing

Then:

julia> include("tmp/julia/getfield.jl") # v1.8.5
  1.923 ns (0 allocations: 0 bytes)
  1.924 ns (0 allocations: 0 bytes)
  1.923 ns (0 allocations: 0 bytes)
  1.923 ns (0 allocations: 0 bytes)

julia> include("tmp/julia/getfield.jl") # v1.9.2
  1.923 ns (0 allocations: 0 bytes)
  12.877 ns (1 allocation: 16 bytes)
  2.134 ns (0 allocations: 0 bytes)
  12.927 ns (1 allocation: 16 bytes)

julia> include("tmp/julia/getfield.jl") # v1.10.0-beta1
  1.953 ns (0 allocations: 0 bytes)
  2.815 ns (0 allocations: 0 bytes)
  15.269 ns (1 allocation: 16 bytes)
  17.970 ns (1 allocation: 16 bytes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceMust go fasterregressionRegression in behavior compared to a previous versionregression 1.9Regression in the 1.9 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions