Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend vec::FromIterator specialization to collect in-place for some iterator pipelines #66383

Closed
wants to merge 54 commits into from

Conversation

the8472
Copy link
Member

@the8472 the8472 commented Nov 13, 2019

This extends the existing vec.into_iter().collect::<Vec>() specialization to cover more cases, including iterator pipelines that flow from IntoIter through Map, Filter, Zip and Enumerate and several others.

Benchmark results with defaults and opt-level = 3, codegen-units=1.

The specialization should be conservative, it is only applied when we know the iterator will fit into the source allocation.

Additionally some existing specializations now applied in a few more code-paths.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 13, 2019
src/libcore/iter/adapters/mod.rs Show resolved Hide resolved
src/libcore/iter/adapters/mod.rs Outdated Show resolved Hide resolved
src/liballoc/vec.rs Outdated Show resolved Hide resolved
src/liballoc/vec.rs Outdated Show resolved Hide resolved
@the8472
Copy link
Member Author

the8472 commented Nov 15, 2019

Replacing the mem::forget with proper drop handling makes the numbers look less rosy. I had to rig the benchmark (using larger items per iteration) to still see an improvement.

How do I run individual benches under perf or at least get their assembly?

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-15T00:55:43.8827446Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-15T00:55:43.9014301Z ##[command]git config gc.auto 0
2019-11-15T00:55:43.9084482Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-15T00:55:43.9135028Z ##[command]git config --get-all http.proxy
2019-11-15T00:55:43.9258868Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66383/merge:refs/remotes/pull/66383/merge
---
2019-11-15T01:01:09.3011325Z    Compiling serde_json v1.0.40
2019-11-15T01:01:10.7206220Z    Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
2019-11-15T01:01:19.5261713Z     Finished release [optimized] target(s) in 1m 11s
2019-11-15T01:01:19.5347754Z tidy check
2019-11-15T01:01:19.6527435Z tidy error: /checkout/src/liballoc/benches/vec.rs:488: line longer than 100 chars
2019-11-15T01:01:19.6600170Z tidy error: /checkout/src/liballoc/vec.rs: too many lines (3015) (add `// ignore-tidy-filelength` to the file to suppress this error)
2019-11-15T01:01:21.5399004Z Found 441 error codes
2019-11-15T01:01:21.5399734Z Found 0 error codes with no tests
2019-11-15T01:01:21.5399996Z Done!
2019-11-15T01:01:21.5400189Z some tidy checks failed
2019-11-15T01:01:21.5400189Z some tidy checks failed
2019-11-15T01:01:21.5400344Z 
2019-11-15T01:01:21.5400500Z 
2019-11-15T01:01:21.5403185Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2019-11-15T01:01:21.5403331Z 
2019-11-15T01:01:21.5403373Z 
2019-11-15T01:01:21.5405727Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2019-11-15T01:01:21.5406159Z Build completed unsuccessfully in 0:01:14
2019-11-15T01:01:21.5406159Z Build completed unsuccessfully in 0:01:14
2019-11-15T01:01:21.5447005Z == clock drift check ==
2019-11-15T01:01:21.5458806Z   local time: Fri Nov 15 01:01:21 UTC 2019
2019-11-15T01:01:21.6297359Z   network time: Fri, 15 Nov 2019 01:01:21 GMT
2019-11-15T01:01:21.6300335Z == end clock drift check ==
2019-11-15T01:01:23.0126180Z 
2019-11-15T01:01:23.0184538Z ##[error]Bash exited with code '1'.
2019-11-15T01:01:23.0210699Z ##[section]Starting: Checkout
2019-11-15T01:01:23.0212289Z ==============================================================================
2019-11-15T01:01:23.0212332Z Task         : Get sources
2019-11-15T01:01:23.0212368Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-15T01:18:26.6409864Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-15T01:18:26.6622732Z ##[command]git config gc.auto 0
2019-11-15T01:18:26.6688146Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-15T01:18:26.6754312Z ##[command]git config --get-all http.proxy
2019-11-15T01:18:26.6907171Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66383/merge:refs/remotes/pull/66383/merge
---
2019-11-15T02:17:24.6946709Z .................................................................................................... 1500/9240
2019-11-15T02:17:30.7545036Z .................................................................................................... 1600/9240
2019-11-15T02:17:39.9800008Z .................................................................................................... 1700/9240
2019-11-15T02:17:48.4822532Z ....i............................................................................................... 1800/9240
2019-11-15T02:17:55.2675132Z ........................................................................................iiiii....... 1900/9240
2019-11-15T02:18:16.9049354Z .................................................................................................... 2100/9240
2019-11-15T02:18:19.3311459Z .................................................................................................... 2200/9240
2019-11-15T02:18:21.9468000Z .................................................................................................... 2300/9240
2019-11-15T02:18:28.9391697Z .................................................................................................... 2400/9240
---
2019-11-15T02:21:26.4309273Z .......................................................................................i............ 4700/9240
2019-11-15T02:21:33.3561575Z ...i................................................................................................ 4800/9240
2019-11-15T02:21:42.8334727Z .................................................................................................... 4900/9240
2019-11-15T02:21:48.3289537Z .................................................................................................... 5000/9240
2019-11-15T02:21:59.7020988Z ..........................................................................................ii.ii..... 5100/9240
2019-11-15T02:22:08.6378659Z .........................i.......................................................................... 5300/9240
2019-11-15T02:22:17.8337384Z .................................................................................................... 5400/9240
2019-11-15T02:22:27.1894500Z .......................................................................i............................ 5500/9240
2019-11-15T02:22:34.9725821Z .................................................................................................... 5600/9240
2019-11-15T02:22:34.9725821Z .................................................................................................... 5600/9240
2019-11-15T02:22:42.6424861Z .................................................................................................... 5700/9240
2019-11-15T02:22:52.2629629Z .........................................................ii...i..ii...........i..................... 5800/9240
2019-11-15T02:23:15.3592249Z .................................................................................................... 6000/9240
2019-11-15T02:23:24.0746702Z .................................................................................................... 6100/9240
2019-11-15T02:23:24.0746702Z .................................................................................................... 6100/9240
2019-11-15T02:23:29.5064265Z ............................................................................i..ii................... 6200/9240
2019-11-15T02:23:59.2750156Z .................................................................................................... 6400/9240
2019-11-15T02:24:01.9145609Z .............................................i...................................................... 6500/9240
2019-11-15T02:24:04.2647560Z .................................................................................................... 6600/9240
2019-11-15T02:24:06.7470913Z ..............................i..................................................................... 6700/9240
---
2019-11-15T02:29:27.7035548Z  finished in 5.927
2019-11-15T02:29:27.7210924Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-15T02:29:27.9264927Z 
2019-11-15T02:29:27.9265893Z running 156 tests
2019-11-15T02:29:30.9220754Z iiii....iii......iii..iiii...i.............................i..i..................i....i...........ii 100/156
2019-11-15T02:29:32.8466685Z .i.i..iiii..............i.........iii.i.........ii......
2019-11-15T02:29:32.8467484Z 
2019-11-15T02:29:32.8468593Z  finished in 5.125
2019-11-15T02:29:32.8656717Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-15T02:29:33.0339279Z 
---
2019-11-15T02:29:35.0088514Z  finished in 2.143
2019-11-15T02:29:35.0301611Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-15T02:29:35.2048170Z 
2019-11-15T02:29:35.2048762Z running 9 tests
2019-11-15T02:29:35.2049527Z iiiiiiiii
2019-11-15T02:29:35.2049855Z 
2019-11-15T02:29:35.2050096Z  finished in 0.174
2019-11-15T02:29:35.2233122Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-15T02:29:35.4092177Z 
---
2019-11-15T02:29:54.8671978Z  finished in 19.643
2019-11-15T02:29:54.8884113Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-15T02:29:55.0809301Z 
2019-11-15T02:29:55.0809534Z running 123 tests
2019-11-15T02:30:19.7834083Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....ii..........iiii..........i...ii...i.......ii. 100/123
2019-11-15T02:30:24.5822444Z i.i.i......iii.i.....ii
2019-11-15T02:30:24.5824270Z 
2019-11-15T02:30:24.5827437Z  finished in 29.693
2019-11-15T02:30:24.5835094Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-15T02:30:24.5836503Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-11-15T02:42:35.5758099Z 
2019-11-15T02:42:35.5759436Z    Doc-tests core
2019-11-15T02:42:40.6329054Z 
2019-11-15T02:42:40.6330104Z running 2421 tests
2019-11-15T02:42:51.6815017Z ......iiiii......................................................................................... 100/2421
2019-11-15T02:43:02.5898362Z .................................................................................ii................. 200/2421
2019-11-15T02:43:28.0793343Z ....i............................................................................................... 400/2421
2019-11-15T02:43:28.0793343Z ....i............................................................................................... 400/2421
2019-11-15T02:43:38.7885461Z ....................................................i..i.................iiii....................... 500/2421
2019-11-15T02:43:58.5701599Z .................................................................................................... 700/2421
2019-11-15T02:44:08.9742356Z .................................................................................................... 800/2421
2019-11-15T02:44:19.4166514Z .................................................................................................... 900/2421
2019-11-15T02:44:29.8506969Z .................................................................................................... 1000/2421
---
2019-11-15T02:48:42.2550635Z 
2019-11-15T02:48:42.2551458Z running 1000 tests
2019-11-15T02:49:02.9787406Z i................................................................................................... 100/1000
2019-11-15T02:49:14.3397850Z .................................................................................................... 200/1000
2019-11-15T02:49:22.4819924Z ...................iii.......i.....i...i......i..................................................... 300/1000
2019-11-15T02:49:27.7678899Z .................................................................................................... 400/1000
2019-11-15T02:49:35.3481455Z ...........................................i..i.................................ii.................. 500/1000
2019-11-15T02:49:49.3628475Z .................................................................................................... 700/1000
2019-11-15T02:49:49.3628475Z .................................................................................................... 700/1000
2019-11-15T02:49:56.8072415Z ..........................iiii...................................................................... 800/1000
2019-11-15T02:50:12.2614885Z .................................................................................................... 900/1000
2019-11-15T02:50:19.9006238Z ................................................iiii................................................ 1000/1000
2019-11-15T02:50:19.9007260Z test result: ok. 980 passed; 0 failed; 20 ignored; 0 measured; 0 filtered out
2019-11-15T02:50:19.9007541Z 
2019-11-15T02:50:19.9049897Z  finished in 192.098
2019-11-15T02:50:19.9065979Z Testing term stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
2019-11-15T03:06:01.2978423Z     Checking compiler_builtins v0.1.18
2019-11-15T03:06:02.3730750Z  Documenting alloc v0.0.0 (/checkout/src/liballoc)
2019-11-15T03:06:05.3299468Z     Finished release [optimized] target(s) in 23.23s
2019-11-15T03:06:05.6937174Z  Documenting core v0.0.0 (/checkout/src/libcore)
2019-11-15T03:06:17.2526923Z error: `[next]` cannot be resolved, ignoring it...
2019-11-15T03:06:17.2529006Z    |
2019-11-15T03:06:17.2529006Z    |
2019-11-15T03:06:17.2529582Z 61 |     /// Callers may assume that calls to [`next()`] or any method taking `&self`
2019-11-15T03:06:17.2530587Z    |
2019-11-15T03:06:17.2531027Z note: lint level defined here
2019-11-15T03:06:17.2531479Z   --> src/libcore/lib.rs:64:9
2019-11-15T03:06:17.2531912Z    |
2019-11-15T03:06:17.2531912Z    |
2019-11-15T03:06:17.2532403Z 64 | #![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
2019-11-15T03:06:17.2533618Z    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
2019-11-15T03:06:17.2533845Z 
2019-11-15T03:06:17.2533845Z 
2019-11-15T03:06:17.2552500Z error: `[next]` cannot be resolved, ignoring it...
2019-11-15T03:06:17.2553923Z    |
2019-11-15T03:06:17.2553923Z    |
2019-11-15T03:06:17.2554611Z 61 |     /// Callers may assume that calls to [`next()`] or any method taking `&self`
2019-11-15T03:06:17.2556177Z    |
2019-11-15T03:06:17.2556706Z    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
2019-11-15T03:06:17.2556881Z 
2019-11-15T03:06:17.6457795Z error: aborting due to 2 previous errors
2019-11-15T03:06:17.6457795Z error: aborting due to 2 previous errors
2019-11-15T03:06:17.6459236Z 
2019-11-15T03:06:17.7511813Z error: Could not document `core`.
2019-11-15T03:06:17.7511970Z 
2019-11-15T03:06:17.7512017Z Caused by:
2019-11-15T03:06:17.7512793Z   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustdoc --edition=2018 --crate-type lib --crate-name core src/libcore/lib.rs --target x86_64-unknown-linux-gnu -o /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/doc --error-format=json --json=diagnostic-rendered-ansi --markdown-css rust.css --markdown-no-toc --generate-redirect-pages --resource-suffix 1.41.0 --index-page /checkout/src/doc/index.md -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps` (exit code: 1)
2019-11-15T03:06:17.7531739Z 
2019-11-15T03:06:17.7531739Z 
2019-11-15T03:06:17.7532949Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "rustdoc" "-Zconfig-profile" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "2" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/src/libtest/Cargo.toml" "-Z" "unstable-options" "-p" "core" "--" "--markdown-css" "rust.css" "--markdown-no-toc" "--generate-redirect-pages" "--resource-suffix" "1.41.0" "--index-page" "/checkout/src/doc/index.md"
2019-11-15T03:06:17.7533116Z 
2019-11-15T03:06:17.7533143Z 
2019-11-15T03:06:17.7544369Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-11-15T03:06:17.7544870Z Build completed unsuccessfully in 1:41:36
2019-11-15T03:06:17.7544870Z Build completed unsuccessfully in 1:41:36
2019-11-15T03:06:17.7596900Z == clock drift check ==
2019-11-15T03:06:17.7610942Z   local time: Fri Nov 15 03:06:17 UTC 2019
2019-11-15T03:06:18.0391673Z   network time: Fri, 15 Nov 2019 03:06:18 GMT
2019-11-15T03:06:18.0392667Z == end clock drift check ==
2019-11-15T03:06:19.4517766Z 
2019-11-15T03:06:19.4623809Z ##[error]Bash exited with code '1'.
2019-11-15T03:06:19.4656446Z ##[section]Starting: Checkout
2019-11-15T03:06:19.4658230Z ==============================================================================
2019-11-15T03:06:19.4658319Z Task         : Get sources
2019-11-15T03:06:19.4658368Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@the8472
Copy link
Member Author

the8472 commented Nov 16, 2019

I have addressed all review issues, extended the benchmarks and restored vectorization performance.
Updated results can be found in the first comment.

@Centril
Copy link
Contributor

Centril commented Nov 16, 2019

cc also @scottmcm @bluss

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Nov 16, 2019

⌛ Trying commit 92dc2b06c8168f6b7e8effcc1b2406e6cfef3bdb with merge 32277c67f9127581d9db3d08b2604f4e8265ac15...

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-11-16T21:42:41.0172224Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-11-16T21:42:41.0377686Z ##[command]git config gc.auto 0
2019-11-16T21:42:41.0444609Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-11-16T21:42:41.0516992Z ##[command]git config --get-all http.proxy
2019-11-16T21:42:41.0675411Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66383/merge:refs/remotes/pull/66383/merge
---
2019-11-16T22:45:44.4151104Z .................................................................................................... 1500/9246
2019-11-16T22:45:50.6633017Z .................................................................................................... 1600/9246
2019-11-16T22:46:00.4055346Z .................................................................................................... 1700/9246
2019-11-16T22:46:09.4590767Z .....i.............................................................................................. 1800/9246
2019-11-16T22:46:16.2910000Z .........................................................................................iiiii...... 1900/9246
2019-11-16T22:46:39.8306291Z .................................................................................................... 2100/9246
2019-11-16T22:46:42.3097497Z .................................................................................................... 2200/9246
2019-11-16T22:46:44.8864491Z .................................................................................................... 2300/9246
2019-11-16T22:46:51.2568351Z .................................................................................................... 2400/9246
---
2019-11-16T22:49:57.6840939Z .........................................................................................i.......... 4700/9246
2019-11-16T22:50:05.2532951Z .....i.............................................................................................. 4800/9246
2019-11-16T22:50:14.9540927Z .................................................................................................... 4900/9246
2019-11-16T22:50:20.7373802Z .................................................................................................... 5000/9246
2019-11-16T22:50:31.9923009Z .............................................................................................ii.ii.. 5100/9246
2019-11-16T22:50:41.8796212Z .............................i...................................................................... 5300/9246
2019-11-16T22:50:48.6809395Z .................................................................................................... 5400/9246
2019-11-16T22:50:59.5668667Z ...........................................................................i........................ 5500/9246
2019-11-16T22:51:07.9379503Z .................................................................................................... 5600/9246
2019-11-16T22:51:07.9379503Z .................................................................................................... 5600/9246
2019-11-16T22:51:14.9349185Z .................................................................................................... 5700/9246
2019-11-16T22:51:25.7221889Z .............................................................ii...i..ii...........i................. 5800/9246
2019-11-16T22:51:49.7251049Z .................................................................................................... 6000/9246
2019-11-16T22:51:57.7186484Z .................................................................................................... 6100/9246
2019-11-16T22:51:57.7186484Z .................................................................................................... 6100/9246
2019-11-16T22:52:02.7527658Z ................................................................................i..ii............... 6200/9246
2019-11-16T22:52:32.3838039Z .................................................................................................... 6400/9246
2019-11-16T22:52:36.6650847Z ................................................i................................................... 6500/9246
2019-11-16T22:52:38.9961835Z .................................................................................................... 6600/9246
2019-11-16T22:52:41.5847481Z ....................................i............................................................... 6700/9246
---
2019-11-16T22:58:16.3112178Z  finished in 5.914
2019-11-16T22:58:16.3316236Z Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-16T22:58:16.5264064Z 
2019-11-16T22:58:16.5265367Z running 156 tests
2019-11-16T22:58:19.6015091Z iiii....iii......iii..iiii...i.............................i..i..................i....i...........ii 100/156
2019-11-16T22:58:22.2753910Z .i..i.iiii..............i.........iii.i.........ii......
2019-11-16T22:58:22.2794558Z 
2019-11-16T22:58:22.2794864Z  finished in 5.255
2019-11-16T22:58:22.2796116Z Check compiletest suite=codegen-units mode=codegen-units (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-16T22:58:22.2796648Z 
---
2019-11-16T22:58:23.8200617Z  finished in 2.210
2019-11-16T22:58:23.8391202Z Check compiletest suite=assembly mode=assembly (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-16T22:58:24.0022359Z 
2019-11-16T22:58:24.0022606Z running 9 tests
2019-11-16T22:58:24.0023424Z iiiiiiiii
2019-11-16T22:58:24.0023832Z 
2019-11-16T22:58:24.0027542Z  finished in 0.163
2019-11-16T22:58:24.0243303Z Check compiletest suite=incremental mode=incremental (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-16T22:58:24.7807558Z 
---
2019-11-16T22:58:45.0392759Z  finished in 21.014
2019-11-16T22:58:45.0617901Z Check compiletest suite=debuginfo mode=debuginfo-gdb+lldb (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-16T22:58:45.2536533Z 
2019-11-16T22:58:45.2536997Z running 123 tests
2019-11-16T22:59:11.6073337Z .iiiii...i.....i..i...i..i.i.i..i.ii..i.i.....i..i....ii..........iiii..........i...ii...i.......ii. 100/123
2019-11-16T22:59:16.5444851Z i.i.i......iii.i.....ii
2019-11-16T22:59:16.5446484Z 
2019-11-16T22:59:16.5447407Z  finished in 31.483
2019-11-16T22:59:16.5454310Z Uplifting stage1 rustc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-16T22:59:16.5455997Z Copying stage2 rustc from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
---
2019-11-16T23:12:16.8913851Z 
2019-11-16T23:12:16.8914763Z    Doc-tests core
2019-11-16T23:12:22.1373527Z 
2019-11-16T23:12:22.1375440Z running 2421 tests
2019-11-16T23:12:33.5880956Z ......iiiii......................................................................................... 100/2421
2019-11-16T23:12:44.2877765Z .................................................................................ii................. 200/2421
2019-11-16T23:13:10.5996184Z ....i............................................................................................... 400/2421
2019-11-16T23:13:10.5996184Z ....i............................................................................................... 400/2421
2019-11-16T23:13:21.4680890Z ....................................................i..i.................iiii....................... 500/2421
2019-11-16T23:13:41.8141914Z .................................................................................................... 700/2421
2019-11-16T23:13:52.7429823Z .................................................................................................... 800/2421
2019-11-16T23:14:02.9717446Z .................................................................................................... 900/2421
2019-11-16T23:14:13.8694283Z .................................................................................................... 1000/2421
---
2019-11-16T23:18:21.2125830Z .............................................. 300/763
2019-11-16T23:18:21.2133966Z ...thread '<unnamed>' panicked at 'explicit panic', src/libstd/io/stdio.rs:854:13
2019-11-16T23:18:21.2522733Z ................................................................................................. 400/763
2019-11-16T23:18:23.3392050Z .................................................................................................... 500/763
2019-11-16T23:18:23.3627316Z ....................thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', src/libcore/result.rs:1187:5
2019-11-16T23:18:23.3646099Z ....thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: RecvErrorthread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "SendError(..)"', src/libcore/result.rs:1187:5
2019-11-16T23:18:23.3654612Z .', src/libcore/result.rs:1187:5
2019-11-16T23:18:23.3677534Z ......thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', src/libcore/result.rs:1187:5
2019-11-16T23:18:23.5673393Z ..........................................thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', src/libcore/result.rs:1187:5
2019-11-16T23:18:23.5712396Z ....thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError.', src/libcore/result.rs:..1187:5..
2019-11-16T23:18:23.5732845Z ..thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', src/libcore/result.rs:1187:5
2019-11-16T23:18:25.6335001Z .......................thread '<unnamed>' panicked at 'explicit panic', src/libstd/sync/mutex.rs:629:13
2019-11-16T23:18:25.6340331Z ...thread '<unnamed>' panicked at 'test panic in inner thread to poison mutex', src/libstd/sync/mutex.rs:584:13
2019-11-16T23:18:25.6358507Z .thread '<unnamed>' panicked at 'test panic in inner thread to poison mutex', src/libstd/sync/mutex.rs:561:13
2019-11-16T23:18:25.6362719Z thread '<unnamed>' panicked at 'explicit panic', src/libstd/sync/mutex.rs:689:13
---
2019-11-16T23:18:34.9604672Z 
2019-11-16T23:18:34.9648815Z running 999 tests
2019-11-16T23:18:57.3239878Z i................................................................................................... 100/999
2019-11-16T23:19:09.4977008Z .................................................................................................... 200/999
2019-11-16T23:19:17.6292897Z ..................iii......i......i...i......i...................................................... 300/999
2019-11-16T23:19:23.6028492Z .................................................................................................... 400/999
2019-11-16T23:19:31.4936876Z ..........................................i..i.................................ii................... 500/999
2019-11-16T23:19:46.6426012Z .................................................................................................... 700/999
2019-11-16T23:19:46.6426012Z .................................................................................................... 700/999
2019-11-16T23:19:54.2377535Z .........................iiii....................................................................... 800/999
2019-11-16T23:20:10.6810441Z .................................................................................................... 900/999
2019-11-16T23:20:18.4470940Z ...............................................iiii................................................
2019-11-16T23:20:18.4471541Z 
2019-11-16T23:20:18.4578731Z  finished in 204.281
2019-11-16T23:20:18.4592698Z Testing term stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
2019-11-16T23:20:18.6865073Z    Compiling term v0.0.0 (/checkout/src/libterm)
---
2019-11-16T23:38:38.5827161Z Rustbook (x86_64-unknown-linux-gnu) - edition-guide
2019-11-16T23:38:38.9995800Z Building stage0 tool linkchecker (x86_64-unknown-linux-gnu)
2019-11-16T23:38:39.2106121Z    Compiling linkchecker v0.1.0 (/checkout/src/tools/linkchecker)
2019-11-16T23:38:41.5526451Z     Finished release [optimized] target(s) in 2.55s
2019-11-16T23:38:43.7758494Z std/iter/trait.SourceIter.html:39: broken link - std/iter/trait.TrustedRandomAccess.html
2019-11-16T23:38:46.9811490Z core/iter/trait.SourceIter.html:39: broken link - core/iter/trait.TrustedRandomAccess.html
2019-11-16T23:38:50.4010987Z thread 'main' panicked at 'found some broken links', src/tools/linkchecker/main.rs:41:9
2019-11-16T23:38:50.4027586Z 
2019-11-16T23:38:50.4027884Z 
2019-11-16T23:38:50.4028731Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/linkchecker" "/checkout/obj/build/x86_64-unknown-linux-gnu/doc"
2019-11-16T23:38:50.4029551Z expected success, got: exit code: 101
---
2019-11-16T23:38:50.4112178Z   local time: Sat Nov 16 23:38:50 UTC 2019
2019-11-16T23:38:50.6887848Z   network time: Sat, 16 Nov 2019 23:38:50 GMT
2019-11-16T23:38:50.6890948Z == end clock drift check ==
2019-11-16T23:38:54.0604633Z 
2019-11-16T23:38:54.0776730Z ##[error]Bash exited with code '1'.
2019-11-16T23:38:54.0833476Z ##[section]Starting: Checkout
2019-11-16T23:38:54.0835882Z ==============================================================================
2019-11-16T23:38:54.0835964Z Task         : Get sources
2019-11-16T23:38:54.0836016Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@@ -53,15 +53,15 @@
//! [`Index`]: ../../std/ops/trait.Index.html
//! [`IndexMut`]: ../../std/ops/trait.IndexMut.html
//! [`vec!`]: ../../std/macro.vec.html

// ignore-tidy-filelength
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that the file went over 3000 LOC which tidy doesn't like. Ideally the file should be refactored into smaller pieces.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any recommendations what should be split out?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a start, the iterators (e.g. Drain) could probably be moved out to a module:

src/liballoc/vec/
    - mod.rs
    - iter.rs

but it's probably best to do the split in a different PR to keep the diff limited.

src/liballoc/collections/binary_heap.rs Outdated Show resolved Hide resolved
src/liballoc/vec.rs Outdated Show resolved Hide resolved
src/liballoc/vec.rs Outdated Show resolved Hide resolved
@Centril
Copy link
Contributor

Centril commented Nov 17, 2019

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Nov 17, 2019

⌛ Trying commit 54797671acec9dedc22af578665dc291abfdb8bf with merge cfe2d15711e1469278c75c80cdb6508be16e8beb...

@bors
Copy link
Contributor

bors commented Nov 17, 2019

☀️ Try build successful - checks-azure
Build commit: cfe2d15711e1469278c75c80cdb6508be16e8beb (cfe2d15711e1469278c75c80cdb6508be16e8beb)

@rust-timer
Copy link
Collaborator

Queued cfe2d15711e1469278c75c80cdb6508be16e8beb with parent 5c5b8af, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit cfe2d15711e1469278c75c80cdb6508be16e8beb, comparison URL.

@the8472 the8472 force-pushed the in-place-iter-collect branch 2 times, most recently from b9fba82 to 89a616a Compare November 17, 2019 11:50
@the8472
Copy link
Member Author

the8472 commented Nov 17, 2019

I don't see how those latest build errors are related to my changes? Any hints how to fix this?

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-7 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-02-02T18:50:11.3989145Z ========================== Starting Command Output ===========================
2020-02-02T18:50:11.4036632Z [command]/bin/bash --noprofile --norc /home/vsts/work/_temp/4f44f0da-2dbf-4509-aa7d-d14855e065d8.sh
2020-02-02T18:50:11.4036819Z 
2020-02-02T18:50:11.4039856Z ##[section]Finishing: Disable git automatic line ending conversion
2020-02-02T18:50:11.4044560Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/66383/merge to s
2020-02-02T18:50:11.4046006Z Task         : Get sources
2020-02-02T18:50:11.4046032Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-02-02T18:50:11.4046058Z Version      : 1.0.0
2020-02-02T18:50:11.4046083Z Author       : Microsoft
---
2020-02-02T18:50:12.1780280Z ##[command]git remote add origin https://github.com/rust-lang/rust
2020-02-02T18:50:12.1855125Z ##[command]git config gc.auto 0
2020-02-02T18:50:12.1918488Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2020-02-02T18:50:12.1972950Z ##[command]git config --get-all http.proxy
2020-02-02T18:50:12.2092328Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/66383/merge:refs/remotes/pull/66383/merge
---
2020-02-02T18:54:55.1416536Z    Compiling serde_json v1.0.40
2020-02-02T18:54:56.4082254Z    Compiling tidy v0.1.0 (/checkout/src/tools/tidy)
2020-02-02T18:55:04.4509862Z     Finished release [optimized] target(s) in 1m 07s
2020-02-02T18:55:04.4589023Z tidy check
2020-02-02T18:55:05.3103627Z tidy error: /checkout/src/libcore/iter/adapters/mod.rs: too many lines (3011) (add `// ignore-tidy-filelength` to the file to suppress this error)
2020-02-02T18:55:06.6296833Z Found 487 error codes
2020-02-02T18:55:06.6297814Z Found 0 error codes with no tests
2020-02-02T18:55:06.6297878Z Done!
2020-02-02T18:55:06.6297914Z some tidy checks failed
2020-02-02T18:55:06.6297914Z some tidy checks failed
2020-02-02T18:55:06.6307363Z 
2020-02-02T18:55:06.6307549Z 
2020-02-02T18:55:06.6308555Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
2020-02-02T18:55:06.6308697Z 
2020-02-02T18:55:06.6308718Z 
2020-02-02T18:55:06.6312157Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
2020-02-02T18:55:06.6312211Z Build completed unsuccessfully in 0:01:15
2020-02-02T18:55:06.6312211Z Build completed unsuccessfully in 0:01:15
2020-02-02T18:55:06.6357359Z == clock drift check ==
2020-02-02T18:55:06.6364984Z   local time: Sun Feb  2 18:55:06 UTC 2020
2020-02-02T18:55:06.7274856Z   network time: Sun, 02 Feb 2020 18:55:06 GMT
2020-02-02T18:55:06.7277068Z == end clock drift check ==
2020-02-02T18:55:07.5045656Z 
2020-02-02T18:55:07.5124449Z ##[error]Bash exited with code '1'.
2020-02-02T18:55:07.5135758Z ##[section]Finishing: Run build
2020-02-02T18:55:07.5148473Z ##[section]Starting: Checkout rust-lang/rust@refs/pull/66383/merge to s
2020-02-02T18:55:07.5150140Z Task         : Get sources
2020-02-02T18:55:07.5150176Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
2020-02-02T18:55:07.5150211Z Version      : 1.0.0
2020-02-02T18:55:07.5150259Z Author       : Microsoft
2020-02-02T18:55:07.5150259Z Author       : Microsoft
2020-02-02T18:55:07.5150295Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
2020-02-02T18:55:07.5150333Z ==============================================================================
2020-02-02T18:55:07.8436905Z Cleaning any cached credential from repository: rust-lang/rust (GitHub)
2020-02-02T18:55:07.8471541Z ##[section]Finishing: Checkout rust-lang/rust@refs/pull/66383/merge to s
2020-02-02T18:55:07.8564502Z Cleaning up task key
2020-02-02T18:55:07.8565337Z Start cleaning up orphan processes.
2020-02-02T18:55:07.8657353Z Terminate orphan process: pid (3693) (python)
2020-02-02T18:55:07.8811483Z ##[section]Finishing: Finalize Job

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@the8472
Copy link
Member Author

the8472 commented Feb 2, 2020

@Dylan-DPC done

@Dylan-DPC-zz
Copy link

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Feb 3, 2020

⌛ Trying commit 2d051db with merge efe77ba...

bors added a commit that referenced this pull request Feb 3, 2020
Extend vec::FromIterator specialization to collect in-place for some iterator pipelines

This extends the existing `vec.into_iter().collect::<Vec>()` specialization to cover more cases, including iterator pipelines that flow from `IntoIter` through `Map`, `Filter`, `Zip` and `Enumerate` and several others.

[Benchmark results](https://gist.github.com/the8472/6d999b2d08a2bedf3b93f12112f96e2f) with defaults and opt-level = 3, codegen-units=1.

The specialization should be conservative, it is only applied when we know the iterator will fit into the source allocation.

Additionally some existing specializations now applied in a few more code-paths.
@bors
Copy link
Contributor

bors commented Feb 3, 2020

☀️ Try build successful - checks-azure
Build commit: efe77ba (efe77bae91ca450dfcf50993449875eb31eacf0f)

@rust-timer
Copy link
Collaborator

Queued efe77ba with parent a2e8030, future comparison URL.

@the8472
Copy link
Member Author

the8472 commented Feb 21, 2020

The top negative item of that perf run is syn-opt, I can't reproduce the result locally.

I'm building rustc stage2 from

  • base commit of my branch
  • the tip of my branch

Then I run rustc-perf rev e8cd7a6

$ RUST_LOG=info ./target/release/collector --filter syn --self-profile --output-repo out bench_local --rustc ~/workspace/rust/build/x86_64-unknown-linux-gnu/stage2/bin/rustc --cargo `which cargo` "syn-s2"
$ RUST_LOG=info ./target/release/collector --filter syn --self-profile --output-repo out bench_local --rustc ~/workspace/rust2/build/x86_64-unknown-linux-gnu/stage2/bin/rustc --cargo `which cargo` "syn-baseline2"`

Screenshot_2020-02-21 rustc performance data

Anything I might be missing?

@blankname
Copy link

blankname commented Feb 23, 2020

@the8472 Probably don't want to focus on minor changes in syn-opt perf see #69060.

The issue mentions a noop run that was faster.

This comment references the issue in relation to a bench where it was slower.
#69072 (comment)

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 2, 2020
@JohnCSimon
Copy link
Member

ping from triage:
@the8472 - can you address the feedback?

@the8472
Copy link
Member Author

the8472 commented Mar 10, 2020

I'm still trying a few things, but running those benchmarks locally takes ages, which makes iterating slow. I'll have to rebase the branch anyway, maybe some of the recent MIR optimizations will reduce the overhead.

@Dylan-DPC-zz
Copy link

Closing this due to inactivity. Thanks for taking the time to contribute to rustc.

@the8472
Copy link
Member Author

the8472 commented Mar 28, 2020

Sorry for the slow responses. I did rebase my branch and ran the webrender-wrench rustc-perf benchmarks locally and the differences vanished. Can I get another perf run?

@the8472
Copy link
Member Author

the8472 commented Apr 1, 2020

Should I make a new PR instead?

@Dylan-DPC-zz
Copy link

@the8472 this can't be reöpened so yeah.

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 3, 2020
specialize some collection and iterator operations to run in-place

This is a rebase and update of rust-lang#66383 which was closed due inactivity.

Recent rustc changes made the compile time regressions disappear, at least for webrender-wrench. Running a stage2 compile and the rustc-perf suite takes hours on the hardware I have at the moment, so I can't do much more than that.

![Screenshot_2020-04-05 rustc performance data](https://user-images.githubusercontent.com/1065730/78462657-5d60f100-76d4-11ea-8a0b-4f3962707c38.png)

In the best case of the `vec::bench_in_place_recycle` synthetic microbenchmark these optimizations can provide a 15x speedup over the regular implementation which allocates a new vec for every benchmark iteration. [Benchmark results](https://gist.github.com/the8472/6d999b2d08a2bedf3b93f12112f96e2f). In real code the speedups are tiny, but it also depends on the allocator used, a system allocator that uses a process-wide mutex will benefit more than one with thread-local pools.

## What was changed

* `SpecExtend` which covered `from_iter` and `extend` specializations was split into separate traits
* `extend` and `from_iter` now reuse the `append_elements` if passed iterators are from slices.
* A preexisting `vec.into_iter().collect::<Vec<_>>()` optimization that passed through the original vec has been generalized further to also cover cases where the original has been partially drained.
* A chain of *Vec<T> / BinaryHeap<T> / Box<[T]>* `IntoIter`s  through various iterator adapters collected into *Vec<U>* and *BinaryHeap<U>* will be performed in place as long as `T` and `U` have the same alignment and size and aren't ZSTs.
* To enable above specialization the unsafe, unstable `SourceIter` and `InPlaceIterable` traits have been added. The first allows reaching through the iterator pipeline to grab a pointer to the source memory. The latter is a marker that promises that the read pointer will advance as fast or faster than the write pointer and thus in-place operation is possible in the first place.
* `vec::IntoIter` implements `TrustedRandomAccess` for `T: Copy` to allow in-place collection when there is a `Zip` adapter in the iterator. TRA had to be made an unstable public trait to support this.

## In-place collectible adapters

* `Map`
* `MapWhile`
* `Filter`
* `FilterMap`
* `Fuse`
* `Skip`
* `SkipWhile`
* `Take`
* `TakeWhile`
* `Enumerate`
* `Zip` (left hand side only, `Copy` types only)
* `Peek`
* `Scan`
* `Inspect`

## Concerns

`vec.into_iter().filter(|_| false).collect()` will no longer return a vec with 0 capacity, instead it will return its original allocation. This avoids the cost of doing any allocation or deallocation but could lead to large allocations living longer than expected.
If that's not acceptable some resizing policy at the end of the attempted in-place collect would be necessary, which in the worst case could result in one more memcopy than the non-specialized case.

## Possible followup work

* split liballoc/vec.rs to remove `ignore-tidy-filelength`
* try to get trivial chains such as `vec.into_iter().skip(1).collect::<Vec<)>>()` to compile to a `memmove` (currently compiles to a pile of SIMD, see rust-lang#69187 )
* improve up the traits so they can be reused by other crates, e.g. itertools. I think currently they're only good enough for internal use
* allow iterators sourced from a `HashSet` to be in-place collected into a `Vec`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.