[Mono-dev] mono numerical performance
jonathan.shore at gmail.com
Sun Nov 20 15:20:43 EST 2011
On Nov 20, 2011, at 2:28 PM, Konrad M. Kruczyński wrote:
> Maybe that's the reason there is no local readonly in the C# language -
> local variables are easily trackable. As to those used in closures (as
> mentioned by Jonathan) - as far as I know, they aren't local variables
> actually but rather fields in compiler-generated class which represents
Yes you are right, closures represent an immutable snapshot of state and hence do not present additional complications. Being less familiar with C#, was thinking that a delegate could track a mutable dependency. Of course it could refer to object references, where the object internals mutate during the invocation.
A more tricky problem, one that I think is handled in the JVM, is when indices are calculated within a loop, for instance array [col * nrows + row] in a matrix class. Assuming a loop over rows and columns, a compiler would need to determine that the condition (col * nrows + row) < array.Length is invariant.
> Btw, about the documenting intent part - some of these cases may
> probably be covered by the Code Contracts.
Contracts can be nice. And in addition to "documenting" and restricting behavior, could also be used by a JIT to determine efficient code generation based on a more constrained problem.
The .NET Code Contracts library seems more like an extension of Debug.Assert(), perhaps a bit too verbose. It would have been interesting to have added a terser form perhaps as part of the language as some languages have done. Not sure whether MS .NET VM is prepared to make use of this information or not, or is purely doing a boolean check in these methods and throwing an assertion exception.
More information about the Mono-devel-list