Skip to content

find_type causes lock contention #706

@BioTurboNick

Description

@BioTurboNick

function find_type(typepath::String)
parts = split(typepath, '.')
# Find a type in the loaded modules by traversing the parts
for mod in Base.loaded_modules_array()
for part in parts
sym = Symbol(part)
(!isa(mod, Module) || !isdefined(mod, sym)) && break
mod = getfield(mod, sym)
end
if mod isa DataType || mod isa UnionAll
# We found a type, so we can stop searching
return mod
end
end
return nothing
end

Every call to find_type calls Base.loaded_modules_array, which 1) globally locks and 2) creates a fresh copy of the array.

Perhaps JLD2 could look up the loaded_modules_array just once on each loading call and carry that forward? (Is this a use case for ScopedValue?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions