# Pros and Cons of passing ObjectRefs in a container

**URL:** <https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289>\
**Category:** Ray Core\
**Created:** [March 17, 2021, 7:56am UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289 "2021-03-17T07:56:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![YarShev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yarshev/32/638_2.png) [@YarShev](https://discuss.ray.io/u/YarShev)\
**Post date:** [March 17, 2021, 7:56am UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289/1 "2021-03-17T07:56:40Z")

</div>

Hi guys,

I would like to ask you about Pros and Cons of passing ObjectRefs in a container (for instance, in a list) to a remote function. Especially, how does it affect the performance if we run it in a cluster?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Yaroslav\_Igoshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yaroslav_igoshev/32/283_2.png) [@Yaroslav\_Igoshev](https://discuss.ray.io/u/Yaroslav_Igoshev)\
**Post date:** [March 18, 2021, 10:22am UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289/2 "2021-03-18T10:22:14Z")

</div>

@sangcho, can you give some thoughts on this, please?

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [March 18, 2021, 6:03pm UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289/3 "2021-03-18T18:03:53Z")

</div>

When the object ref is passed into a remote function, ray.get is automatically (implicitly) called.

```auto
@ray.remote
def f(ref):
    print(ref) # It prints the numpy array, not the ref

ref = ray.put(np.ones(1024*1024, dtype=np.unit8))
ray.get(f.remote(ref))

```

But if you pass references within a list, ray.get is not implicitly called.

```auto
@ray.remote
def f(ref):
    print(ref) # It prints a [ref], and ray.get is not called until you explicitly call it.
    print(ray.get(ref)) # This is the numpy array.
 
ref = ray.put(np.ones(1024*1024, dtype=np.unit8))
ray.get(f.remote([ref]))

```

Regarding performance, there’s nothing I am aware of that can impact the performance. If you pass the ref within a container, you can control memory a bit better (since you can obtain objects from the plasma store only when you really need it), but with zero-copy read, it wouldn’t be a big deal in many cases.

---

<div class="post-metadata">

**Author:** ![Yaroslav\_Igoshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yaroslav_igoshev/32/283_2.png) [@Yaroslav\_Igoshev](https://discuss.ray.io/u/Yaroslav_Igoshev)\
**Post date:** [March 18, 2021, 7:31pm UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289/4 "2021-03-18T19:31:34Z")

</div>

@sangcho , yes, that is true. However, is that an issue for ray in a cluster if we pass a list of ObjectRefs in a remote function? I mean in that case ray won’t have enough information for better scheduling and placement. Is it right?

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [March 19, 2021, 10:18pm UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289/5 "2021-03-19T22:18:40Z")

</div>

That’s a good question! Ray doesn’t use the object store memory information for scheduling (we are planning to do, but even after that, it won’t be a too big deal). I cannot think of any bad implication of this except that ray.get could take more time (but scheduling could be faster, so it is complemented)

---

<div class="post-metadata">

**Author:** ![Yaroslav\_Igoshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yaroslav_igoshev/32/283_2.png) [@Yaroslav\_Igoshev](https://discuss.ray.io/u/Yaroslav_Igoshev)\
**Post date:** [March 22, 2021, 7:11pm UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289/6 "2021-03-22T19:11:07Z")

</div>

@sangcho , to summarize, there is nothing bad if we pass a list of ObjectRefs to a remote function. The drawback is that ray.get can take more time. If I am not correct or there is something to add, please, let me know.

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [March 22, 2021, 11:43pm UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289/7 "2021-03-22T23:43:33Z")

</div>

To be clear, my answer is there’s nothing that I am aware of that can impact the performance. But what you said sounds right to me.

---

<div class="post-metadata">

**Author:** ![Yaroslav\_Igoshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yaroslav_igoshev/32/283_2.png) [@Yaroslav\_Igoshev](https://discuss.ray.io/u/Yaroslav_Igoshev)\
**Post date:** [March 23, 2021, 4:49am UTC](https://discuss.ray.io/t/pros-and-cons-of-passing-objectrefs-in-a-container/1289/8 "2021-03-23T04:49:54Z")

</div>

@sangcho , okay, thank you!
