Skip to content

Scoped Value performance issue #58330

Open
@gbaraldi

Description

@gbaraldi

While looking at why scoped values weren't performing as expected I saw that we are doing a bunch of runtime calls where I expected it to be none

using Base.ScopedValues

const sval = ScopedValue(1)

function foo()
    with(sval => 2) do
        sval[]
    end
end

code_typed(with, Tuple{var"#foo##0#foo##1", Pair{ScopedValue{Int64}, Int64}})

You can see here that Main.sval is not getting const propped as it should being a const global (this is not new with binding partitions) so I believe the issue is the OptimizedGenerics pass that is losing the information for that global somewhere.

40%58 =   builtin Base.getfield(Main.sval, :has_default)::Bool
└───       goto #45 if not %58
41%60 =   builtin Base.getfield(Main.sval, :default)::Int64%61 =    invoke Core.OptimizedGenerics.KeyValue.get(%49::Base.PersistentDict{ScopedValue, Any}, Main.sval::ScopedValue{Int64})::Union{Nothing, Tuple{Any}}%62 =   builtin (%61 === Base.nothing)::Bool

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