diff --git a/src/utils/utils.jl b/src/utils/utils.jl index e82d8a83..ddd11ba9 100644 --- a/src/utils/utils.jl +++ b/src/utils/utils.jl @@ -425,14 +425,25 @@ function get_initial_timestamp(data::TimeSeries.TimeArray) return TimeSeries.timestamp(data)[1] end -function get_module(module_name) +# Looking up modules with Base.root_module is slow; cache them. +const g_cached_modules = Dict{String, Module}() + +function get_module(module_name::AbstractString) + cached_module = get(g_cached_modules, module_name, nothing) + if !isnothing(cached_module) + return cached_module + end + # root_module cannot find InfrastructureSystems if it hasn't been installed by the # user (but has been installed as a dependency to another package). - return if module_name == "InfrastructureSystems" + mod = if module_name == "InfrastructureSystems" InfrastructureSystems else Base.root_module(Base.__toplevel__, Symbol(module_name)) end + + g_cached_modules[module_name] = mod + return mod end get_type_from_strings(module_name, type) =