Skip to content

Performance For Generics

IT Notes → C# @ December 22, 2020

  • When we use object instead of generic variable for value types, we waste on boxing effort and for both value and reference we waste at the point of down casting to individual type.
  • Also type safety at the time of down casting is not considered.
  • Server compiler compiles it into IL where there is placeholder for types and meta information regarding them.
  • For value types client compiler converts IL to machine code where value is replaced and for reference replace it with objects. Code reuse not object reuse is done wherever possible.
  • You can expect around 200% performance gain on value types and 100% on reference types.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x