{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/22200","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/22200/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/22200/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/22200/events","html_url":"https://github.com/rust-lang/rust/pull/22200","id":57401629,"number":22200,"title":"std: Optimize Vec::from_iter","user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"huonw","id":1203825,"avatar_url":"https://avatars.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"milestone":null,"comments":10,"created_at":"2015-02-12T00:50:25Z","updated_at":"2015-02-12T18:25:26Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/22200","html_url":"https://github.com/rust-lang/rust/pull/22200","diff_url":"https://github.com/rust-lang/rust/pull/22200.diff","patch_url":"https://github.com/rust-lang/rust/pull/22200.patch"},"body":"This PR is an optimization of the `FromIterator` implementation of `Vec`\r\n\r\nBenchmark: https://gist.github.com/alexcrichton/03d666159a28a80e7c70\r\n\r\nBefore:\r\n\r\n    test macro_repeat1     ... bench:        57 ns/iter (+/- 1)\r\n    test macro_repeat2     ... bench:        56 ns/iter (+/- 1)\r\n    test map_clone1        ... bench:       828 ns/iter (+/- 13)\r\n    test map_clone2        ... bench:       828 ns/iter (+/- 8)\r\n    test repeat1           ... bench:      1104 ns/iter (+/- 10)\r\n    test repeat2           ... bench:      1106 ns/iter (+/- 11)\r\n\r\nAfter:\r\n\r\n    test macro_repeat1     ... bench:        75 ns/iter (+/- 21)\r\n    test macro_repeat2     ... bench:        59 ns/iter (+/- 31)\r\n    test map_clone1        ... bench:        34 ns/iter (+/- 22)\r\n    test map_clone2        ... bench:        52 ns/iter (+/- 21)\r\n    test repeat1           ... bench:        34 ns/iter (+/- 11)\r\n    test repeat2           ... bench:        33 ns/iter (+/- 12)\r\n\r\nThe idea behind this optimization is to avoid all bounds checks for space\r\nalready allocated into the vector. This may involve running the iterator twice,\r\nbut the first run of the iterator should be optimizable to a memcpy or memset if\r\npossible.\r\n\r\nThe same treatment can in theory be applied to `Vec::extend` but the benchmarks\r\nfor that currently get *worse* if the change is applied. This appears to be some\r\nLLVM optimizations going awry but it's seems prudent to land at least the\r\n`collect` portion beforehand."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/74123754","html_url":"https://github.com/rust-lang/rust/pull/22200#issuecomment-74123754","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/22200","id":74123754,"user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T18:25:26Z","updated_at":"2015-02-12T18:25:26Z","body":"@bors: r+ 985fc7d"}}