# Zero-copy deserialization with recursive dictionaries/lists

**URL:** <https://discuss.ray.io/t/zero-copy-deserialization-with-recursive-dictionaries-lists/1890>\
**Category:** Ray Core\
**Created:** [April 25, 2021, 10:56am UTC](https://discuss.ray.io/t/zero-copy-deserialization-with-recursive-dictionaries-lists/1890 "2021-04-25T10:56:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drew\_Barclay](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/drew_barclay/32/890_2.png) [@Drew\_Barclay](https://discuss.ray.io/u/Drew_Barclay)\
**Post date:** [April 25, 2021, 10:56am UTC](https://discuss.ray.io/t/zero-copy-deserialization-with-recursive-dictionaries-lists/1890/1 "2021-04-25T10:56:03Z")

</div>

Hi there,

I’m curious on the limits of Ray’s zero-copy deserializability. My current understanding is that if a function returns a (large, over 100KB by default) numpy array, it will be put in the Plasma object store, so that any other executing tasks can use it without copying any memory.

Does this guarantee apply to Numpy arrays stored in dictionaries? What about dictionaries of dictionaries?

As per the docs at [Serialization — Ray v2.0.0.dev0](https://docs.ray.io/en/master/serialization.html#serialization), `You can often avoid serialization issues by using only native types (e.g., numpy arrays or lists/dicts of numpy arrays and other primitive types), or by using Actors hold objects that cannot be serialized.` But it’s not clear to me whether it handles _recursive_ lists/dictionaries.

Would zero-copy deserialization work with the following? Or, how can I tell whether zero-copy deserialization occurred so I can test it myself?

a)

```auto
def a(x):
    return {'a': large_numpy_array(x)}

```

b)

```auto
def b(x):
    return {'a': {'b': large_numpy_array(x)}}

```

c)

```auto
def c(x):
    return {'a': [{'b': large_numpy_array(x)}], 'c': large_numpy_array(x)}

```

---

<div class="post-metadata">

**Author:** ![ericl](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ericl/32/133_2.png) [@ericl](https://discuss.ray.io/u/ericl)\
**Post date:** [August 3, 2021, 8:58pm UTC](https://discuss.ray.io/t/zero-copy-deserialization-with-recursive-dictionaries-lists/1890/2 "2021-08-03T20:58:27Z")

</div>

Yep, Ray supports all of these cases with zero-copy. There’s an easy way to tell:

> > > x\_id = ray.put({“x”: {“y”: np.zeros(5)}})  
> > > x = ray.get(x\_id)  
> > > x[“x”][“y”].flags  
> > > C\_CONTIGUOUS : True  
> > > F\_CONTIGUOUS : True  
> > > OWNDATA : False  
> > > WRITEABLE : False  
> > > ALIGNED : True  
> > > WRITEBACKIFCOPY : False  
> > > UPDATEIFCOPY : False

WRITABLE = False, which is sure sign that we’re using zero-copy memory from plasma.
