# Serialize() is prohibitively slow for recursive structs. What am I missing?

**URL:** <https://discourse.julialang.org/t/serialize-is-prohibitively-slow-for-recursive-structs-what-am-i-missing/76276>\
**Category:** New to Julia\
**Tags:** serialization, recursion\
**Created:** [February 12, 2022, 1:32am UTC](https://discourse.julialang.org/t/serialize-is-prohibitively-slow-for-recursive-structs-what-am-i-missing/76276 "2022-02-12T01:32:21Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![SortofDamocles](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sortofdamocles/32/15709_2.png) [@SortofDamocles](https://discourse.julialang.org/u/SortofDamocles)\
**Post date:** [February 14, 2022, 7:56pm UTC](https://discourse.julialang.org/t/serialize-is-prohibitively-slow-for-recursive-structs-what-am-i-missing/76276/14 "2022-02-14T19:56:56Z")

</div>

Oh, brilliant idea just to have a single `make_immutable` pass after building the tree! This is a write-once, read-many situation so that is a _very_ easy improvement I can make.

I spent a couple of hours last night working through `Serialization.jl` with an eye toward a custom dispatch for `serialize`. In the meantime, it was easy enough to flatten the tree into a vector of `Int`s representing all the `childvalues` instances and serialize that instead. Even with the overhead of flattening and expanding, I’ve already gotten a huge increase in throughput.

---

_[View the full topic](https://discourse.julialang.org/t/serialize-is-prohibitively-slow-for-recursive-structs-what-am-i-missing/76276)._
