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
{{ message }}
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Accidentally during memory profiling of our app, I've discovered that contracts for IDictionary https://github.com/Microsoft/CodeContracts/blob/master/Microsoft.Research/Contracts/MsCorlib/System.Collections.Generic.IDictionary.cs
Contains a lot of contracts like Contract.Requires(!ReferenceEquals(key, null));
and this lead to boxing of a value type keys (e.g. keys like ints, Guids are quite common) and performance penalties. Looks like a bug.
I suspect that those contracts should be more clever than that and consider that generic type could be a ValueType and such check does not make sense at all.
In the meantime I need a workaround: Is it possible to ask somehow code contracts rewriter do not use contracts for implemented interfaces? Some way to ignore them for a specific type only?
IIRC there's an attribute you can apply to your specific types to tell the rewriter to ignore it. I forget the specifics, I think it's covered in the manual.
Activity
yaakov-h commentedon Jun 24, 2017
IIRC there's an attribute you can apply to your specific types to tell the rewriter to ignore it. I forget the specifics, I think it's covered in the manual.
AndirNotes commentedon Jun 25, 2017
Oh, thank you. Found it. Quite unobvious attribute name, but it works.
[ContractOption("contract", "inheritance", false)]