# Why is deepcopy() -ing Sets slower than Arrays of the same size?

**URL:** <https://discourse.julialang.org/t/why-is-deepcopy-ing-sets-slower-than-arrays-of-the-same-size/53020>\
**Category:** Performance\
**Tags:** deepcopy\
**Created:** [January 8, 2021, 1:28am UTC](https://discourse.julialang.org/t/why-is-deepcopy-ing-sets-slower-than-arrays-of-the-same-size/53020 "2021-01-08T01:28:13Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![anon56330260](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anon56330260](https://discourse.julialang.org/u/anon56330260)\
**Post date:** [January 8, 2021, 3:23am UTC](https://discourse.julialang.org/t/why-is-deepcopy-ing-sets-slower-than-arrays-of-the-same-size/53020/5 "2021-01-08T03:23:39Z")

</div>

Half storage? How can you do that? Array{Nothing,1} allocates only 80 bytes even if it contains many elements.

```julia
julia> @allocated a = Array{Int}(undef,10000000)
80000080

julia> @allocated a = Array{Nothing}(undef,10000000)
80

```

The problem here is that you have only 5 elements in this set, but a hash table with `n = 16` slots (with 16 UInt). Also, if you check the keys of the set, you will find it contains 16 keys:

```julia
julia> set.dict.keys
16-element Vector{Int64}:

```

So another half time is spent to copy the slots and these additional keys.

---

_[View the full topic](https://discourse.julialang.org/t/why-is-deepcopy-ing-sets-slower-than-arrays-of-the-same-size/53020)._
