{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/1167","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/1167/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/1167/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/1167/events","html_url":"https://github.com/dotnet/coreclr/issues/1167","id":90274291,"number":1167,"title":"Make all structs that claim to be thread-safe dereference `this` at most once per entrypoint","user":{"login":"AArnott","id":3548,"avatar_url":"https://avatars.githubusercontent.com/u/3548?v=3","gravatar_id":"","url":"https://api.github.com/users/AArnott","html_url":"https://github.com/AArnott","followers_url":"https://api.github.com/users/AArnott/followers","following_url":"https://api.github.com/users/AArnott/following{/other_user}","gists_url":"https://api.github.com/users/AArnott/gists{/gist_id}","starred_url":"https://api.github.com/users/AArnott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AArnott/subscriptions","organizations_url":"https://api.github.com/users/AArnott/orgs","repos_url":"https://api.github.com/users/AArnott/repos","events_url":"https://api.github.com/users/AArnott/events{/privacy}","received_events_url":"https://api.github.com/users/AArnott/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-23T03:16:10Z","updated_at":"2015-06-23T07:13:53Z","closed_at":null,"body":"`ImmutableArray<T>` goes to great lengths to be thread-safe by [never dereferencing `this` more than once per public entrypoint][1] (to fix bug #191). Other structs in the Framework do *not* take this care (such as `DateTime`, `Nullable<T>`, or `System.Int32`), despite [claiming to be thread-safe in MSDN documentation][2].\r\n\r\nShould we take the same care for the other structs? \r\n\r\nThe community [has been fascinated][3] by the pattern in `ImmutableArray<T>` and brought up that it might make sense to spread it around more.\r\n\r\nSee also the [same issue in corefx](/dotnet/corefx/issues/2119).\r\n [1]: https://github.com/dotnet/corefx/blob/1dc118cc46f88e4889a23190b450d89e565967fd/src/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray%601.cs#L18-L33\r\n [2]: https://msdn.microsoft.com/en-us/library/System.DateTime(v=vs.110).aspx\r\n [3]: http://stackoverflow.com/questions/30957211/what-advantage-is-there-to-storing-this-in-a-local-variable-in-a-struct-method/30957262"},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/114387527","html_url":"https://github.com/dotnet/coreclr/issues/1167#issuecomment-114387527","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/1167","id":114387527,"user":{"login":"hadibrais","id":5206180,"avatar_url":"https://avatars.githubusercontent.com/u/5206180?v=3","gravatar_id":"","url":"https://api.github.com/users/hadibrais","html_url":"https://github.com/hadibrais","followers_url":"https://api.github.com/users/hadibrais/followers","following_url":"https://api.github.com/users/hadibrais/following{/other_user}","gists_url":"https://api.github.com/users/hadibrais/gists{/gist_id}","starred_url":"https://api.github.com/users/hadibrais/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadibrais/subscriptions","organizations_url":"https://api.github.com/users/hadibrais/orgs","repos_url":"https://api.github.com/users/hadibrais/repos","events_url":"https://api.github.com/users/hadibrais/events{/privacy}","received_events_url":"https://api.github.com/users/hadibrais/received_events","type":"User","site_admin":false},"created_at":"2015-06-23T07:13:53Z","updated_at":"2015-06-23T07:13:53Z","body":"This is only practical if the size of the struct is equal to the size of a reference, which is not the case for **DateTime** and **Nullable&lt;T&gt;** and many other structs on x86. That's because some synchronization mechanism has to be used to copy the instance atomically which can add significant overhead.\r\n\r\nIf we make this change, all structs will be divided into two categories: those whose size is equal to a reference and those who aren't. If we want to apply this change to all types in the first category, I believe it would be better to modify the JIT compiler so that it automatically makes a copy of the instance on every method call. This eliminates any maintainability overhead associated with this issue and makes sure all methods of all such structs follow this pattern automatically."}}