# How to efficiently save and read dictionaries in Julia?

**URL:** https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337
**Category:** Performance
**Tags:** question, dictionary, io, dictionaries
**Created:** [May 4, 2023, 6:28pm UTC](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337 "2023-05-04T18:28:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![F\_A](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/f_a/32/53159_2.png) [@F\_A](https://discourse.julialang.org/u/F_A)
#### Post date: [May 4, 2023, 6:28pm UTC](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337/1 "2023-05-04T18:28:13Z")

</div>

Hi,

I’d like to save a dictionary to a file with more than 12500 entries. I’ve read some suggestion [here](https://stackoverflow.com/questions/31013516/what-is-the-correct-way-to-save-and-retrieve-dictionaries-in-julia) and [here](https://discourse.julialang.org/t/how-do-i-save-my-dictionary-as-a-csv-or-excel-file/36791). But I was wondering whether these are the most efficient way to do so?

Thanks a lot.

---

<div class="post-metadata">

### Author: ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)
#### Post date: [May 4, 2023, 6:30pm UTC](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337/2 "2023-05-04T18:30:28Z")

</div>

How about using [Serialization](https://docs.julialang.org/en/v1/stdlib/Serialization/)?

---

<div class="post-metadata">

### Author: ![Perrin\_Meyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/perrin_meyer/32/15686_2.png) [@Perrin\_Meyer](https://discourse.julialang.org/u/Perrin_Meyer)
#### Post date: [May 4, 2023, 6:58pm UTC](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337/3 "2023-05-04T18:58:55Z")

</div>

I’ve had good luck with BSON.jl (binary JSON file). I am wrapping a Fortran code that generates 100MB of data per run which I place in a Dict{}, and it loads/saves very fast (I’ve never benchmarked, but it its so fast for me its not an issue).

---

<div class="post-metadata">

### Author: ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)
#### Post date: [May 4, 2023, 7:02pm UTC](https://discourse.julialang.org/t/how-to-efficiently-save-and-read-dictionaries-in-julia/98337/4 "2023-05-04T19:02:43Z")

</div>

It looks like `Serialization.serialize()` writes a few bytes as headers and dumps the bytes of an object directly. I think the computation overhead is much lower than that the BSON has. But of course, it would be nice to see comparative studies.
