Skip to content

Calculate Vec capacities in librustc #52438

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

Merged
merged 1 commit into from
Jul 21, 2018
Merged

Conversation

ljedrz
Copy link
Contributor

@ljedrz ljedrz commented Jul 16, 2018

Calculate the required capacity of a few vectors in rustc based on the number of elements they are populated with.

@rust-highfive

This comment has been minimized.

@rust-lang rust-lang deleted a comment from rust-highfive Jul 16, 2018
@XAMPPRocky
Copy link
Member

r? @estebank

@rust-highfive

This comment has been minimized.

@XAMPPRocky XAMPPRocky added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 16, 2018
@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 16, 2018

Spurious error again; please retry.

@Mark-Simulacrum
Copy link
Member

Retried. cc @nnethercote -- some of these are iterating over the data that'll be inserted into the vector to calculate the length; do you know off-hand if that's a bad idea or not?

@rust-highfive

This comment has been minimized.

@nnethercote
Copy link
Contributor

some of these are iterating over the data that'll be inserted into the vector to calculate the length; do you know off-hand if that's a bad idea or not?

Not sure. If the data will be iterated over subsequently and it's not too large, it probably doesn't matter. Profiling is the ultimate test.

(BTW, the PR lacks a description, as does the patch. That makes any kind of commentary more difficult. Even a single sentence of explanation would be helpful.)

@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 16, 2018

@nnethercote I added a short description (initially I just didn't think it was too informative); please advise if I'm missing anything.

@rust-lang rust-lang deleted a comment from rust-highfive Jul 16, 2018
@rust-lang rust-lang deleted a comment from rust-highfive Jul 16, 2018
@nnethercote
Copy link
Contributor

@ljedrz: Often the "why" is more interesting than the "what", especially for PRs and commit messages. Do you have measurements showing that this speeds things up?

@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 17, 2018

I'd be happy to measure it; could you tell me which benchmarks I should run and how to do it? I couldn't find that information online.

@rust-highfive
Copy link
Contributor

Your PR failed on Travis (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.

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)

@oli-obk
Copy link
Contributor

oli-obk commented Jul 17, 2018

@bors try

Let's do a perf run I guess?

@bors
Copy link
Collaborator

bors commented Jul 17, 2018

⌛ Trying commit 0bb54a1 with merge 07079a7...

bors added a commit that referenced this pull request Jul 17, 2018
Calculate Vec capacities in librustc

Calculate the required capacity of a few vectors in rustc based on the number of elements they are populated with.
@nnethercote
Copy link
Contributor

@oli-obk started an online perf run for you, but you can also do local benchmarking and profiling. Documentation is here: https://github.com/rust-lang-nursery/rustc-perf/tree/master/collector

What prompted you to write this patch? It adds some complexity, and generally you'd want to have some other clear benefit to compensate. The default growth strategy for Vec is usually reasonable. Going to the effort of precomputing a length like this is usually only worthwhile if the number of Vecs created is large, or the Vecs themselves have many elements.

@bors
Copy link
Collaborator

bors commented Jul 17, 2018

💔 Test failed - status-travis

@rust-highfive
Copy link
Contributor

The job dist-x86_64-linux of your PR failed on Travis (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.
travis_fold:end:services

travis_fold:start:git.checkout
travis_time:start:1691dd16
$ git clone --depth=2 --branch=try https://github.com/rust-lang/rust.git rust-lang/rust
---
[00:18:51]    Compiling rustc_borrowck v0.0.0 (file:///checkout/src/librustc_borrowck)
[00:18:51]    Compiling rustc_passes v0.0.0 (file:///checkout/src/librustc_passes)
[00:19:11]    Compiling rustc_codegen_utils v0.0.0 (file:///checkout/src/librustc_codegen_utils)
[00:19:24]    Compiling rustc_lint v0.0.0 (file:///checkout/src/librustc_lint)
[00:19:35] error[E0599]: no method named `iter` found for type `std::collections::btree_map::Keys<'_, rustc::session::config::OutputType, std::option::Option<std::path::PathBuf>>` in the current scope
[00:19:35]     --> librustc_driver/driver.rs:1358:22
[00:19:35]      |
[00:19:35] 1358 |         output_types.iter().fold(0, |acc, ot| acc +
[00:19:35] 
[00:19:35] error: aborting due to previous error
[00:19:35] 
[00:19:35] For more information about this error, try `rustc --explain E0599`.
[00:19:35] For more information about this error, try `rustc --explain E0599`.
[00:19:35] error: Could not compile `rustc_driver`.
[00:19:35] 
[00:19:35] Caused by:
[00:19:35]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name rustc_driver librustc_driver/lib.rs --color always --error-format json --crate-type dylib --emit=dep-info,link -C prefer-dynamic -C opt-level=2 -C metadata=f7646c9abc3d02c6 -C extra-filename=-f7646c9abc3d02c6 --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C linker=clang -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps --extern arena=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libarena-6d643f75b30009ec.so --extern env_logger=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libenv_logger-0a93173f03a79b8d.rlib --extern graphviz=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libgraphviz-09a8465c475acbfe.so --extern log=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblog-96863e4e4a7d8742.rlib --extern rustc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc-50b4354a63d955e7.so --extern rustc_rayon=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_rayon-37c946810bf339eb.rlib --extern rustc_allocator=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_allocator-a22f5323a757a1a5.so --extern rustc_borrowck=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_borrowck-0b78be5e49495de3.so --extern rustc_codegen_utils=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_codegen_utils-ddfd7bb605afc401.so --extern rustc_data_structures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_data_structures-7b2393552f7c05ab.so --extern rustc_errors=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_errors-5a587f583bd26ea0.so --extern rustc_incremental=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_incremental-1f45a21db1899b6d.so --extern rustc_lint=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_lint-0c6a22e4bf4525d1.so --extern rustc_metadata=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_metadata-e2cdb405d3015fe5.so --extern rustc_mir=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_mir-beaee3be21b57d8d.so --extern rustc_passes=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_passes-c5404bfc39dae280.so --extern rustc_plugin=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_plugin-981f27df1cd6e3a9.so --extern rustc_privacy=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_privacy-bfec5ac3788190b9.so --extern rustc_resolve=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_resolve-2a478c753fc3f86e.so --extern rustc_save_analysis=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_save_analysis-75820b40cd20d4fd.so --extern rustc_target=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_target-5aa06a687b1a439d.so --extern rustc_traits=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_traits-b246e0e47fc183bc.so --extern rustc_typeck=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_typeck-486be882e192b694.so --extern scoped_tls=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libscoped_tls-2d0488f0587a9fe8.rlib --extern serialize=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libserialize-5615a04cb21f88e7.so --extern serialize=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libserialize-5615a04cb21f88e7.rlib --extern syntax=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax-4f33c70c5f92f8b7.so --extern syntax_ext=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax_ext-5a0613786e04edc1.so --extern syntax_pos=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax_pos-4e87684380615cae.so -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/backtrace-sys-fcd4d8eb5dc11f1a/out -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/miniz-sys-571491b5b700df39/out` (exit code: 101)

[00:19:35] travis_time:end:stage0-rustc:start=1531808415710893194,finish=1531809214704997753,duration=798994104559

[00:19:35] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu
[00:19:35] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu
[00:19:35] Build completed unsuccessfully in 0:14:18
[00:19:35] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:19:35] expected success, got: exit code: 101
[00:19:35] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1119:9
travis_time:end:02ebf96f:start=1531808039214594879,finish=1531809214969628033,duration=1175755033154

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 1.
travis_time:start:04a045ee
---
travis_time:end:061379ae:start=1531809215287034224,finish=1531809215293549675,duration=6515451
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:00207a5f
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:02571af6
travis_time:start:02571af6
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:1ecec07f
$ dmesg | grep -i kill

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)

@bors bors 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 Jul 17, 2018
@rust-highfive
Copy link
Contributor

The job dist-x86_64-linux of your PR failed on Travis (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.
travis_fold:end:services

travis_fold:start:git.checkout
travis_time:start:1691dd16
$ git clone --depth=2 --branch=try https://github.com/rust-lang/rust.git rust-lang/rust
---
[00:18:51]    Compiling rustc_borrowck v0.0.0 (file:///checkout/src/librustc_borrowck)
[00:18:51]    Compiling rustc_passes v0.0.0 (file:///checkout/src/librustc_passes)
[00:19:11]    Compiling rustc_codegen_utils v0.0.0 (file:///checkout/src/librustc_codegen_utils)
[00:19:24]    Compiling rustc_lint v0.0.0 (file:///checkout/src/librustc_lint)
[00:19:35] error[E0599]: no method named `iter` found for type `std::collections::btree_map::Keys<'_, rustc::session::config::OutputType, std::option::Option<std::path::PathBuf>>` in the current scope
[00:19:35]     --> librustc_driver/driver.rs:1358:22
[00:19:35]      |
[00:19:35] 1358 |         output_types.iter().fold(0, |acc, ot| acc +
[00:19:35] 
[00:19:35] error: aborting due to previous error
[00:19:35] 
[00:19:35] For more information about this error, try `rustc --explain E0599`.
[00:19:35] For more information about this error, try `rustc --explain E0599`.
[00:19:35] error: Could not compile `rustc_driver`.
[00:19:35] 
[00:19:35] Caused by:
[00:19:35]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name rustc_driver librustc_driver/lib.rs --color always --error-format json --crate-type dylib --emit=dep-info,link -C prefer-dynamic -C opt-level=2 -C metadata=f7646c9abc3d02c6 -C extra-filename=-f7646c9abc3d02c6 --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C linker=clang -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps --extern arena=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libarena-6d643f75b30009ec.so --extern env_logger=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libenv_logger-0a93173f03a79b8d.rlib --extern graphviz=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libgraphviz-09a8465c475acbfe.so --extern log=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblog-96863e4e4a7d8742.rlib --extern rustc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc-50b4354a63d955e7.so --extern rustc_rayon=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_rayon-37c946810bf339eb.rlib --extern rustc_allocator=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_allocator-a22f5323a757a1a5.so --extern rustc_borrowck=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_borrowck-0b78be5e49495de3.so --extern rustc_codegen_utils=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_codegen_utils-ddfd7bb605afc401.so --extern rustc_data_structures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_data_structures-7b2393552f7c05ab.so --extern rustc_errors=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_errors-5a587f583bd26ea0.so --extern rustc_incremental=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_incremental-1f45a21db1899b6d.so --extern rustc_lint=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_lint-0c6a22e4bf4525d1.so --extern rustc_metadata=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_metadata-e2cdb405d3015fe5.so --extern rustc_mir=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_mir-beaee3be21b57d8d.so --extern rustc_passes=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_passes-c5404bfc39dae280.so --extern rustc_plugin=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_plugin-981f27df1cd6e3a9.so --extern rustc_privacy=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_privacy-bfec5ac3788190b9.so --extern rustc_resolve=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_resolve-2a478c753fc3f86e.so --extern rustc_save_analysis=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_save_analysis-75820b40cd20d4fd.so --extern rustc_target=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_target-5aa06a687b1a439d.so --extern rustc_traits=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_traits-b246e0e47fc183bc.so --extern rustc_typeck=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_typeck-486be882e192b694.so --extern scoped_tls=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libscoped_tls-2d0488f0587a9fe8.rlib --extern serialize=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libserialize-5615a04cb21f88e7.so --extern serialize=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libserialize-5615a04cb21f88e7.rlib --extern syntax=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax-4f33c70c5f92f8b7.so --extern syntax_ext=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax_ext-5a0613786e04edc1.so --extern syntax_pos=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax_pos-4e87684380615cae.so -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/backtrace-sys-fcd4d8eb5dc11f1a/out -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/miniz-sys-571491b5b700df39/out` (exit code: 101)

[00:19:35] travis_time:end:stage0-rustc:start=1531808415710893194,finish=1531809214704997753,duration=798994104559

[00:19:35] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu
[00:19:35] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host x86_64-unknown-linux-gnu --target x86_64-unknown-linux-gnu
[00:19:35] Build completed unsuccessfully in 0:14:18
[00:19:35] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:19:35] expected success, got: exit code: 101
[00:19:35] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1119:9
travis_time:end:02ebf96f:start=1531808039214594879,finish=1531809214969628033,duration=1175755033154

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 1.
travis_time:start:04a045ee
---
travis_time:end:061379ae:start=1531809215287034224,finish=1531809215293549675,duration=6515451
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:00207a5f
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:02571af6
travis_time:start:02571af6
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:1ecec07f
$ dmesg | grep -i kill

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)

@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 17, 2018

I'll fix the error and do a perf run locally.

@ljedrz ljedrz force-pushed the rustc_vec_capacity branch from 0bb54a1 to 21956d3 Compare July 17, 2018 07:32
@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 17, 2018

Hmm, I can't build rust-perf due to

error[E0425]: cannot find function `exec` in this scope
   --> collector\src/bin/rustc-fake.rs:139:9
    |
139 |         exec(&mut cmd);
    |         ^^^^ not found in this scope

I fixed the PR; @oli-obk can you try please?

@rust-highfive
Copy link
Contributor

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (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.
[00:17:56]    Compiling rustc_lsan v0.0.0 (file:///checkout/src/librustc_lsan)
[00:17:57]    Compiling rustc_tsan v0.0.0 (file:///checkout/src/librustc_tsan)
[00:17:57]    Compiling rustc_asan v0.0.0 (file:///checkout/src/librustc_asan)
[00:17:58]    Compiling rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:18:42] error: could not parse/generate dep info at: /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/core-1cbcabaa1ea822b5.d
[00:18:42] To learn more, run the command again with --verbose.
[00:18:42] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:18:42] expected success, got: exit code: 101
[00:18:42] expected success, got: exit code: 101
[00:18:42] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1119:9
[00:18:42] travis_fold:end:stage1-std

[00:18:42] travis_time:end:stage1-std:start=1531813986336194463,finish=1531814042293753182,duration=55957558719


[00:18:42] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:18:42] Build completed unsuccessfully in 0:15:06
[00:18:43] make: *** [all] Error 1
[00:18:43] Makefile:28: recipe for target 'all' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:122c7394
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:22a1ec40:start=1531814042867792741,finish=1531814042874915860,duration=7123119
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:15573fcc
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:11b9ca10
travis_time:start:11b9ca10
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0a73083e
$ dmesg | grep -i kill

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)

@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 17, 2018

[00:18:42] error: could not parse/generate dep info at: /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/core-1cbcabaa1ea822b5.d 😕?

{
let mut worklist = Vec::with_capacity(access_levels.map.len() +
if tcx.sess.entry_fn.borrow().is_some() { 1 } else { 0 }
);
Copy link
Member

Choose a reason for hiding this comment

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

This can be created from an iterator and .collect().

self.type_variables.borrow().num_vars() +
self.int_unification_table.borrow().len() +
self.float_unification_table.borrow().len()
);
Copy link
Member

Choose a reason for hiding this comment

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

This can be created from an iterator and .collect().

@@ -1353,7 +1353,8 @@ fn generated_output_paths(
exact_name: bool,
crate_name: &str,
) -> Vec<PathBuf> {
let mut out_filenames = Vec::new();
let mut out_filenames = Vec::with_capacity(sess.opts.output_types.len());
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't appear to be correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's later shrunk at 1380; processing keys() before the loop (which was in my initial commit) caused a really uninformative error to occur during stage 1 build.

Copy link
Member

Choose a reason for hiding this comment

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

Then it's a better idea not to touch it at all. This is in the driver, and runs once per compilation, AFAICT, so it's not really worth optimizing (unless you can rewrite it to an iterator, that is).

self.region_bounds.len() +
self.trait_bounds.len() +
self.projection_bounds.len()
);
Copy link
Member

Choose a reason for hiding this comment

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

This can be created from an iterator and .collect().

@eddyb
Copy link
Member

eddyb commented Jul 19, 2018

In general we should really avoid Vec::with_capacity, and push calls, if we can use iterators.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 19, 2018

@eddyb do you want these to be refactored to iterators + collect even if perf shows no benefits? (With the alternative being to close this PR)

Otherwise I say we do a perf run and see if there's any point to doing this at all.

@bors
Copy link
Collaborator

bors commented Jul 19, 2018

☀️ Test successful - status-travis
State: approved= try=True

@ljedrz ljedrz force-pushed the rustc_vec_capacity branch from 340e1ee to 4978a48 Compare July 20, 2018 14:35
@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 20, 2018

@eddyb I addressed your comments, does it look good now?

{
let worklist = access_levels.map.iter().map(|(&id, _)| id).chain(
// Seed entry point
(*tcx.sess.entry_fn.borrow()).and_then(|(id, _, _)| Some(id))
Copy link
Member

Choose a reason for hiding this comment

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

.and_then(|x| Some(y)) is always .map(|x| y) AFAIK

Copy link
Member

Choose a reason for hiding this comment

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

Oh and you shouldn't need the *, using by-value Option methods will do it for you.

let args_capacity = self.args.iter().fold(0, |acc, arg| acc +
if arg.pad.is_some() { 1 } else { 0 } +
if let PassMode::Pair(_, _) = arg.mode { 2 } else { 1 }
);
Copy link
Member

Choose a reason for hiding this comment

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

You can use map and sum.

for projection in &self.projection_bounds {
vec.push(projection.to_predicate());
}
Some(trait_ref.to_predicate())
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here, and_then can be just map.

@kennytm
Copy link
Member

kennytm commented Jul 20, 2018

@rust-timer build 435ce0bad1c0bc79ec8f0591eba110a92492e6ff

@rust-timer
Copy link
Collaborator

Success: Queued 435ce0bad1c0bc79ec8f0591eba110a92492e6ff with parent 0fc4501, comparison URL.

@kennytm kennytm added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 20, 2018
@ljedrz ljedrz force-pushed the rustc_vec_capacity branch from 4978a48 to 8a29409 Compare July 20, 2018 18:06
@ljedrz
Copy link
Contributor Author

ljedrz commented Jul 20, 2018

@eddyb done.

{
let worklist = access_levels.map.iter().map(|(&id, _)| id).chain(
// Seed entry point
(tcx.sess.entry_fn.borrow()).map(|(id, _, _)| id)
Copy link
Member

Choose a reason for hiding this comment

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

You don't need the parens either, sorry I wasn't clear before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I should've noticed that; done.

@ljedrz ljedrz force-pushed the rustc_vec_capacity branch from 8a29409 to e3d14c4 Compare July 20, 2018 20:02
@eddyb
Copy link
Member

eddyb commented Jul 20, 2018

@bors r+ Thanks!

@bors
Copy link
Collaborator

bors commented Jul 20, 2018

📌 Commit e3d14c4 has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 20, 2018
@bors
Copy link
Collaborator

bors commented Jul 21, 2018

⌛ Testing commit e3d14c4 with merge bf7afee...

bors added a commit that referenced this pull request Jul 21, 2018
Calculate Vec capacities in librustc

Calculate the required capacity of a few vectors in rustc based on the number of elements they are populated with.
@bors
Copy link
Collaborator

bors commented Jul 21, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing bf7afee to master...

@bors bors merged commit e3d14c4 into rust-lang:master Jul 21, 2018
@ljedrz ljedrz deleted the rustc_vec_capacity branch July 21, 2018 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-perf Status: Waiting on a perf run to be completed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.