{"action":"opened","issue":{"url":"https://api.github.com/repos/rust-lang/rfcs/issues/2445","repository_url":"https://api.github.com/repos/rust-lang/rfcs","labels_url":"https://api.github.com/repos/rust-lang/rfcs/issues/2445/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rfcs/issues/2445/comments","events_url":"https://api.github.com/repos/rust-lang/rfcs/issues/2445/events","html_url":"https://github.com/rust-lang/rfcs/issues/2445","id":325671695,"number":2445,"title":"Allow specifying a minimum size for `Vec`","user":{"login":"Vurich","id":29733394,"avatar_url":"https://avatars0.githubusercontent.com/u/29733394?v=4","gravatar_id":"","url":"https://api.github.com/users/Vurich","html_url":"https://github.com/Vurich","followers_url":"https://api.github.com/users/Vurich/followers","following_url":"https://api.github.com/users/Vurich/following{/other_user}","gists_url":"https://api.github.com/users/Vurich/gists{/gist_id}","starred_url":"https://api.github.com/users/Vurich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vurich/subscriptions","organizations_url":"https://api.github.com/users/Vurich/orgs","repos_url":"https://api.github.com/users/Vurich/repos","events_url":"https://api.github.com/users/Vurich/events{/privacy}","received_events_url":"https://api.github.com/users/Vurich/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-23T11:54:50Z","updated_at":"2018-05-23T11:54:50Z","closed_at":null,"author_association":"NONE","body":"At the moment when a vector is created it doesn't allocate anything, but then when a single element is pushed to it it grows to hold precisely 4 elements. As further elements are pushed it doubles each time. That first allocation is a problem, though. It's quite common to use `SmallVec` in performance-sensitive code when there is an \"expected maximum\", a value which is normally not exceeded but may be exceeded in edge-cases. However, [profiling shows](http://troubles.md/posts/improving-smallvec/) that using a `Vec` with `with_capacity` is often faster than using `SmallVec` because of the reduced complexity.\r\n\r\nThis has a couple of problems though. Firstly, this isn't a drop-in replacement like `SmallVec` is. You need to replace every call to `new` with `with_capacity` and `.collect()` will still use the same minimum allocation size (although this is rarely a problem because of `size_hint`). Worst is that if you create a vector and then never push anything to it then you have a wasted allocation and deallocation.\r\n\r\nYou could have a wrapper around `Vec` that checks the capacity and allocates the supplied number of elements on first allocation but that's an extra cost on every insertion. The most efficient method would be to have that \"precisely 4\" be configurable somehow, probably with const generics (#2000). Because this couldn't be implemented today, I have written this as an issue rather than a PR."}}
{"actor":{"display_login":"Vurich"}}