You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Classes that don't pass their arrays out by reference; and only directly instantiate them (new T[n]) (rather than setting the array field to something passed by argument or result of external call, could have their element stores changed from covariant stores to invariant stores.
@Suchiman I like your idea of enabling this optimization without requiring code changes everywhere! We can start with implementing it in ILLinker to measure the benefit and prove its usefulness, and maybe later in Roslyn. We have taken the same journey for SkipLocalsInit. The implementation in ILLinker can:
Do escape analysis to identify all arrays that are just used as internal implementation detail (that do not escape outside the assembly - assuming there is no private reflection) and that do not use array covariance
Use alternative more efficient sequence for storing elements into them.
publicpartialclassList<T>{privateT[]_items;publicvoidAdd(Titem){_version++;T[]array=_items;intsize=_size;if((uint)size<(uint)array.Length){_size=size+1;array[size]=item;// array element store}else{AddWithResize(item);}}}
Could have the il changed from something like
ldloc.0
ldloc.1
ldarg.1
stelem !T // Covariant store
So far we've not been using illink as a performance optimization tools. While some of the transforms it does might have performance effect, their main goal is pretty much always size reduction.
If the optimization can be done within a single method's body, then I would say it belongs to the compiler (Roslyn).
If the optimization needs a global program view, then that's something we don't have a tool for yet. Potential places:
JIT
NativeAOT compiler (but that's really JIT as well)
Global IL optimization tool - this could be added to illink, or it could be a separate new tool.
I think that if we want to pursue this, the right place to start would be to start the discussion in the context of roslyn or JIT.
Classes that don't pass their arrays out by reference; and only directly instantiate them (
new T[n]
) (rather than setting the array field to something passed by argument or result of external call, could have their element stores changed from covariant stores to invariant stores.From https://github.com/dotnet/corefx/issues/23689#issuecomment-378283974
For example the store in coreclr
List<T>.Add(T)
Could have the il changed from something like
To something like
/cc @jkotas @mjp41 @VSadov @jaredpar
The text was updated successfully, but these errors were encountered: