Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You take "it will enhance the performance" as a given, but are you really sure about this? Structs perform better than classes in <em>very specific</em> circumstances. I'm generalizing for simplicity, but the scenarios chiefly are:</p> <ul> <li>They're immutable.</li> <li>They're small, e.g. usually no more than 3 - 4 fields.</li> <li>You're generating <em>tons</em> (often millions or more) of them over an extremely short time span.</li> <li>You're working with them in tight loops.</li> <li>The code paths that they travel through are optimized for those specific structs and do not perform boxing / unboxing operations.</li> </ul> <p>There are others, but that's just off the top of my head. And even then, we're talking about often minuscule performance gains. As in <em>microseconds</em> minuscule.</p> <p>Even if you can guarantee that your view models are immutable and tiny, the other conditions don't hold. Assuming one view model per request, your web server is not going to handle millions of requests per second. Furthermore, the MVC framework does not work with these in tight loops and does not contain code paths optimized for this particular struct. The MVC framework will end up performing tons of boxing / unboxing operations on your value types as a result.</p> <p>Bottom line - don't micro-optimize or over-engineer your solution. Classes are just fine. And when optimization is concerned, <strong>always measure</strong> to make sure you're devoting your time to a worthwhile venture. Don't bother with trivialities when there are bigger fish to fry.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload