intern/cache array instances created via collection expressions when the contents are literal/constant #80429
Replies: 2 comments
-
|
We do have a sort of "caching" today for collection expressions of certain We could consider an expanded "caching" optimization for collection expressions targeting "read-only" types. |
Beta Was this translation helpful? Give feedback.
-
|
It's not something addressable for C# compiler. Mutation can easily happen when the array is passed to a different method. If it's provable to be immutable, then it must be non-escaping, then the JIT compiler can cancel the array object itself. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider this code:
It's immutable and all contents is known at compile time.
The compiler should maybe "intern" this? Emit as a static variable?
Beta Was this translation helpful? Give feedback.
All reactions