{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/corefx/issues/5147","labels_url":"https://api.github.com/repos/dotnet/corefx/issues/5147/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/5147/comments","events_url":"https://api.github.com/repos/dotnet/corefx/issues/5147/events","html_url":"https://github.com/dotnet/corefx/pull/5147","id":124286635,"number":5147,"title":"Improve memory use of HashSet constructed from HashSet.","user":{"login":"JonHanna","id":1253369,"avatar_url":"https://avatars.githubusercontent.com/u/1253369?v=3","gravatar_id":"","url":"https://api.github.com/users/JonHanna","html_url":"https://github.com/JonHanna","followers_url":"https://api.github.com/users/JonHanna/followers","following_url":"https://api.github.com/users/JonHanna/following{/other_user}","gists_url":"https://api.github.com/users/JonHanna/gists{/gist_id}","starred_url":"https://api.github.com/users/JonHanna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonHanna/subscriptions","organizations_url":"https://api.github.com/users/JonHanna/orgs","repos_url":"https://api.github.com/users/JonHanna/repos","events_url":"https://api.github.com/users/JonHanna/events{/privacy}","received_events_url":"https://api.github.com/users/JonHanna/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/corefx/labels/2%20-%20In%20Progress","name":"2 - In Progress","color":"CCCCCC"},{"url":"https://api.github.com/repos/dotnet/corefx/labels/cla-already-signed","name":"cla-already-signed","color":"009800"},{"url":"https://api.github.com/repos/dotnet/corefx/labels/performance","name":"performance","color":"fbca04"},{"url":"https://api.github.com/repos/dotnet/corefx/labels/System.Collections","name":"System.Collections","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/dotnet/corefx/milestones/4","html_url":"https://github.com/dotnet/corefx/milestones/1.0.0-rtm","labels_url":"https://api.github.com/repos/dotnet/corefx/milestones/4/labels","id":1248719,"number":4,"title":"1.0.0-rtm","description":"Q1 2016 (https://github.com/aspnet/Home/wiki/Roadmap)","creator":{"login":"joshfree","id":1302850,"avatar_url":"https://avatars.githubusercontent.com/u/1302850?v=3","gravatar_id":"","url":"https://api.github.com/users/joshfree","html_url":"https://github.com/joshfree","followers_url":"https://api.github.com/users/joshfree/followers","following_url":"https://api.github.com/users/joshfree/following{/other_user}","gists_url":"https://api.github.com/users/joshfree/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfree/subscriptions","organizations_url":"https://api.github.com/users/joshfree/orgs","repos_url":"https://api.github.com/users/joshfree/repos","events_url":"https://api.github.com/users/joshfree/events{/privacy}","received_events_url":"https://api.github.com/users/joshfree/received_events","type":"User","site_admin":false},"open_issues":250,"closed_issues":122,"state":"open","created_at":"2015-08-10T18:04:00Z","updated_at":"2016-01-05T22:39:33Z","due_on":"2016-03-31T07:00:00Z","closed_at":null},"comments":12,"created_at":"2015-12-30T00:32:10Z","updated_at":"2016-01-06T00:37:04Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/5147","html_url":"https://github.com/dotnet/corefx/pull/5147","diff_url":"https://github.com/dotnet/corefx/pull/5147.diff","patch_url":"https://github.com/dotnet/corefx/pull/5147.patch"},"body":"If a `HashSet` is constructed from an existing `HashSet` then use the current approach if the count is above a particular ratio to the capacity, but if it is below that ratio (small enough that if created just from those items and then added to the next resize would still not reach that capacity) use an optimised version of `AddIfNotPresent` to add each item.\r\n\r\nFixes #5141 \r\n\r\n@justinvp this combines your suggestion about an optimised version of `AddIfNotPresent` with mine of using the current approach above a certain threshold of count/capacity. I took that threshold as being `ExpandPrime(count + 1)` though there's no perfect value (the best value would depend on what additions where later done, and how long the produced set would be kept in memory, so it can't be perfectly deduced).\r\n\r\nDone on top of the two commits for #5131 rather than repeat things that need to be included in this.\r\n\r\nI pretty much ignored the idea of optimising `UnionWith`. That certainly could be done along the same lines, but the `AddValue` I have here couldn't be quite as tightly optimised, with the skip on tests for the item being present and the skips on incrementing the count and version having to be undone.\r\n\r\nAt the very least this needs more tests before I take off the WIP tag.\r\n\r\nContains the commits that were previously in #5131, so Fixes #5130."},"comment":{"url":"https://api.github.com/repos/dotnet/corefx/issues/comments/169178968","html_url":"https://github.com/dotnet/corefx/pull/5147#issuecomment-169178968","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/5147","id":169178968,"user":{"login":"JonHanna","id":1253369,"avatar_url":"https://avatars.githubusercontent.com/u/1253369?v=3","gravatar_id":"","url":"https://api.github.com/users/JonHanna","html_url":"https://github.com/JonHanna","followers_url":"https://api.github.com/users/JonHanna/followers","following_url":"https://api.github.com/users/JonHanna/following{/other_user}","gists_url":"https://api.github.com/users/JonHanna/gists{/gist_id}","starred_url":"https://api.github.com/users/JonHanna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonHanna/subscriptions","organizations_url":"https://api.github.com/users/JonHanna/orgs","repos_url":"https://api.github.com/users/JonHanna/repos","events_url":"https://api.github.com/users/JonHanna/events{/privacy}","received_events_url":"https://api.github.com/users/JonHanna/received_events","type":"User","site_admin":false},"created_at":"2016-01-06T00:37:04Z","updated_at":"2016-01-06T00:37:04Z","body":"@stephentoub I picked that nit and simplified the tests. I agree its worth checking on whether optimised version of `Add` is worth having, but for some reason this isn't building in Release for me on any branch (though other projects are) which stymies reasonable uses of `[Benchmark]`. I suspect I have something silly in my local set-up, since it was building fine in CI. I'll try to figure that out."}}