0

It's a question about performance

I have a big object with a huge amount of fields (and maybe with a nested objects too).

I have a page component, it receives this object from server.

I have some child-components inside page component. One component needs a several fields from the object, should i pass them as a single prop for every field, or i can pass a whole object? Is it affects to performance?

Renhor
  • 160
  • 6
  • You ask if it faster to pass a reference or a deep copy. But it is most likely not an issue of performance but readability – Estradiaz Apr 08 '20 at 21:24
  • Am i passing a reference when passing the whole object? – Renhor Apr 08 '20 at 21:29
  • think about: var obj = {a: {b: 1}}, What is the value of obj.a ? It is just the reference to {b:1} – Estradiaz Apr 08 '20 at 22:27
  • Straight answer: pass the whole object. It's only a reference so performance is not an issue and it's also cleaner in the template, and less tedious. It might be less clear to someone else (or yourself in the future) what the purpose of the object prop is vs individual props, but that may vary. – Dan Apr 08 '20 at 23:53
  • The problem is not performance but design. A child can mess up the object. At some point you can forget which fields a child needs and how to not break it if object structure changes. See the same issue but for React, https://stackoverflow.com/questions/52621169/react-props-should-i-pass-the-object-or-its-properties-does-it-make-much-diffe – Estus Flask Apr 09 '20 at 06:59

0 Answers0