# Performance of Dict

**URL:** <https://discourse.julialang.org/t/performance-of-dict/30993>\
**Category:** Performance\
**Created:** [November 12, 2019, 7:52am UTC](https://discourse.julialang.org/t/performance-of-dict/30993 "2019-11-12T07:52:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![natgeo-wong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/natgeo-wong/32/10965_2.png) [@natgeo-wong](https://discourse.julialang.org/u/natgeo-wong)\
**Post date:** [November 12, 2019, 7:52am UTC](https://discourse.julialang.org/t/performance-of-dict/30993/1 "2019-11-12T07:52:16Z")

</div>

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).

```julia
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

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 12, 2019, 9:17am UTC](https://discourse.julialang.org/t/performance-of-dict/30993/2 "2019-11-12T09:17:32Z")

</div>

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.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

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](https://docs.julialang.org/en/v1/manual/performance-tips/#Avoid-containers-with-abstract-type-parameters-1)
