kkost
kkost

Reputation: 3740

How good is ValueTuple for large objects?

I going to return big List of objects as one of the parameters in my ValueTuple. Somethings like this:

(bool success, List<TemplateModel> data string error)> Get(string templateName);

As far as ValueTuple is a struct and List inside of struct I suppose have to store in heap. So there shouldn't be any kind of performance issue. Is this make sense? Does this approach have any pitfalls?

Upvotes: 1

Views: 205

Answers (1)

Andrew Skirrow
Andrew Skirrow

Reputation: 3451

Both List<string> and string are reference types so will be stored on the heap. The tuple itself will only contain a reference to these data items.

The size of the reference itself doesn't depend on the number of items in the list or characters in the string. It's usually 32 bits or maybe 64 bits at most.

Most of the time micro-optimisations of this nature won't have any noticeable impact on performance.

Upvotes: 3

Related Questions