Performance of Dict

Hi!

I tend to use the Dict functionality of Julia pretty often to store information (e.g. attributes of various parameters that contain both strings and integers). But I’ve heard that Dict can slow down the performance of Julia code. Is this true?

For reference, the Dict is defined at the beginning of the function (or is used as an input to a function). A specific key might be called repeatedly in for loops. Would this affect performance?

And example code that I use that includes usage of Dicts is shown below (note that the code is unfinished so things might look broken).

function iscaresort(parvec::Array,root::Dict)

    @info "$(Dates.now()) - Resorting the following Isca GCM output variables ..."
    pinfo = iscaparameterload(parvec);

    fol,fnc = iscadinfo(root["raw"]); ndir = length(fol); nttypes = length(fnc);

    lon = ncread(fnc,"lon"); nlon = length(lon);
    lat = ncread(fnc,"lat"); nlat = length(lat);
    pre = ncread(fnc,"pre");
    nt  = length(ncread(fnc,time)); tinfo = iscatime(fnc[ii],nt);
    dim = [nlon,nlat,nt];

    for yr = 1 : ndir; cd(joinpath(root["raw"],fol[yr]))

        for par in parvec; pinfo = iscaparameter(par)

            data = iscaresortextract(pinfo,ncattr,fnc)

        end

    end

    cd(root["isca"])

end

You may be better off with a NamedTuple, but it is hard to say more without context, especially and MWE we can run and inspect.

A Dict would be especially harmful when it is not concretely typed.

https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-containers-with-abstract-type-parameters-1