Open hamarb123 opened 4 months ago
Looking through the samples I would say that essentially there are three issues:
Deconstruct
seems to be always emitting a defensive copy pretty much always. This seems like an omission in the code. The copies are happening because we pass the receiver through EvaluateSideEffectingArgumentToTemp
. Given this is a ref
it can change between reads hence a copy is generated. In these specific cases though it's not needed. @jcouv, @RikkiGibson any thoughts?readonly
members correctly.foreach
doesn't account for readonly
members correctly.Even so ... probably rate this on the lower end of optimizations. Will likely end up as "help-wanted".
When a member is marked as
readonly
, a defensive copy need not be made, since the member will not mutate the struct. These are some instances of where we could avoid more defensive copies.Version Used:
Sharplab.io Also reproduces with compiler included in .NET 8.0.100 SDK.
Steps to Reproduce:
Link
Expected Behavior:
Members marked as "defensive copy (unnecessary)" do not emit a defensive copy.
Actual Behavior:
Members marked as "defensive copy (unnecessary)" do emit a defensive copy. The rest are correct.