Skip to content

Add fast path for maybe-initializedness in liveness #141667

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 5 commits into from
May 31, 2025

Conversation

lqd
Copy link
Member

@lqd lqd commented May 27, 2025

r? @matthewjasper

Correct me if I'm wrong Matthew, but my understanding is that

  1. MaybeInitializedPlaces is currently eagerly computed, in do_mir_borrowck
  2. but this data is only used in liveness
  3. and liveness::trace actually only uses it for drop-liveness

This PR moves the computation to liveness::trace which looks to be its only use-site. We also add a fast path there, so that it's only computed by drop-liveness.

This is interesting because 1) liveness is only computed for relevant live locals, 2) drop-liveness is only computed for relevant live locals with >0 drop points; 0 is the common case from our benchmarks, as far as I can tell, so even just computing the entire data lazily helps.

It seems possible to also reduce the domain here, and speed up the analysis for the cases where it has to be computed -- so I've left a fixme for that, and may look into it soon.

(I've come upon this while doing implementation work for polonius, so don't be too enamored with possible wins: the goal is to reduce the eventual polonius overhead and make it more palatable 😓)

lqd added 5 commits May 27, 2025 21:21
This dataflow analysis is only used by `liveness::trace`. We move it
there to make it lazy.
Only drop-liveness checks for maybe-initializedness of move paths, and
it does so only for the relevant live locals that have drop points.

This adds a fast path by computing this dataflow analysis only when checking for such
initializedness. This avoids this expensive computation for the common
case.

For example, it avoids computing initializedness for 20K locals in the
`cranelift-codegen` benchmark, it has 7K relevant live locals but none
with drop points. That saves 900ms on end-to-end compilation times.
This mir-opt test used the maybe-init dataflow analysis but it's now
lazy and doesn't emit the graphviz graph when it's not needed anymore.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 27, 2025
@lqd
Copy link
Member Author

lqd commented May 27, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 27, 2025
@bors
Copy link
Collaborator

bors commented May 27, 2025

⌛ Trying commit ddeae14 with merge 12882ca...

bors added a commit that referenced this pull request May 27, 2025
Add fast path for maybe-initializedness in liveness

r? `@matthewjasper`

Correct me if I'm wrong Matthew, but my understanding is that
1. `MaybeInitializedPlaces` is currently eagerly computed, in `do_mir_borrowck`
2. but this data is only used in liveness
3. and `liveness::trace` actually only uses it for drop-liveness

This PR moves the computation to `liveness::trace` which looks to be its only use-site. We also add a fast path there, so that it's only computed by drop-liveness.

This is interesting because 1) liveness is only computed for relevant live locals, 2) drop-liveness is only computed for relevant live locals with >0 drop points; 0 is the common case from our benchmarks, as far as I can tell, so even just computing the entire data lazily helps.

It seems possible to also reduce the domain here, and speed up the analysis for the cases where it has to be computed -- so I've left a fixme for that, and may look into it soon.

(I've come upon this while doing implementation work for polonius, so don't be too enamored with possible wins: the goal is to reduce the eventual polonius overhead and make it more palatable 😓)
bors added a commit that referenced this pull request May 27, 2025
Add fast path for maybe-initializedness in liveness

r? `@matthewjasper`

Correct me if I'm wrong Matthew, but my understanding is that
1. `MaybeInitializedPlaces` is currently eagerly computed, in `do_mir_borrowck`
2. but this data is only used in liveness
3. and `liveness::trace` actually only uses it for drop-liveness

This PR moves the computation to `liveness::trace` which looks to be its only use-site. We also add a fast path there, so that it's only computed by drop-liveness.

This is interesting because 1) liveness is only computed for relevant live locals, 2) drop-liveness is only computed for relevant live locals with >0 drop points; 0 is the common case from our benchmarks, as far as I can tell, so even just computing the entire data lazily helps.

It seems possible to also reduce the domain here, and speed up the analysis for the cases where it has to be computed -- so I've left a fixme for that, and may look into it soon.

(I've come upon this while doing implementation work for polonius, so don't be too enamored with possible wins: the goal is to reduce the eventual polonius overhead and make it more palatable 😓)
@bors
Copy link
Collaborator

bors commented May 27, 2025

⌛ Trying commit ddeae14 with merge 4027458...

@bors
Copy link
Collaborator

bors commented May 28, 2025

☀️ Try build successful - checks-actions
Build commit: 4027458 (4027458d5b513ac0b53db5bf760d44b944806706)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4027458): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.9% [-10.5%, -0.1%] 70
Improvements ✅
(secondary)
-0.5% [-1.1%, -0.2%] 58
All ❌✅ (primary) -0.9% [-10.5%, -0.1%] 70

Max RSS (memory usage)

Results (primary 1.4%, secondary 3.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.9% [1.2%, 2.5%] 5
Regressions ❌
(secondary)
3.5% [3.4%, 3.5%] 3
Improvements ✅
(primary)
-1.4% [-1.4%, -1.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.4% [-1.4%, 2.5%] 6

Cycles

Results (primary -6.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-6.0% [-11.6%, -1.7%] 6
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -6.0% [-11.6%, -1.7%] 6

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 779.523s -> 778.77s (-0.10%)
Artifact size: 366.37 MiB -> 366.40 MiB (0.01%)

@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented May 28, 2025

📌 Commit ddeae14 has been approved by matthewjasper

It is now in the queue for this repository.

@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-review Status: Awaiting review from the assignee but also interested parties. labels May 28, 2025
/// initialized.
flow_inits: ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>,
/// initialized. Computed lazily when needed by drop-liveness.
flow_inits: Option<ResultsCursor<'a, 'tcx, MaybeInitializedPlaces<'a, 'tcx>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

this could be a OnceCell and avoid the need for the few &mut selfs added in this commit.

https://doc.rust-lang.org/stable/std/cell/struct.OnceCell.html#method.get_or_try_init

@bors
Copy link
Collaborator

bors commented May 31, 2025

⌛ Testing commit ddeae14 with merge ec28ae9...

@bors
Copy link
Collaborator

bors commented May 31, 2025

☀️ Test successful - checks-actions
Approved by: matthewjasper
Pushing ec28ae9 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 31, 2025
@bors bors merged commit ec28ae9 into rust-lang:master May 31, 2025
8 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 31, 2025
Copy link

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 7a7bcbb (parent) -> ec28ae9 (this PR)

Test differences

Show 33421 test diffs

Stage 1

  • edit_distance::tests::test_method_name_similarity_score: [missing] -> pass (J0)
  • errors::verify_ast_lowering_async_bound_only_for_fn_traits_33: [missing] -> pass (J0)
  • errors::verify_ast_passes_extern_fn_qualifiers_23: [missing] -> pass (J0)
  • errors::verify_parse_attr_after_generic_140: [missing] -> pass (J0)
  • errors::verify_parse_missing_trait_in_trait_impl_77: [missing] -> pass (J0)
  • errors::verify_passes_confusables_88: [missing] -> pass (J0)
  • graph::scc::tests::test_max_branch: [missing] -> pass (J0)
  • lints::verify_lint_named_argument_used_positionally_139: [missing] -> pass (J0)
  • parser::tests::different_note_2: [missing] -> pass (J0)
  • session_diagnostics::verify_driver_impl_unstable_feature_usage_16: [missing] -> pass (J0)
  • sort::tests::stable::correct_dyn_val_random_s95: [missing] -> ignore (J1)
  • sort::tests::unstable::correct_u128_random: [missing] -> ignore (J1)
  • collections::btree::node::tests::test_partial_eq: [missing] -> pass (J2)
  • floats::f16::test_round: [missing] -> pass (J2)
  • floats::f64::test_is_finite: [missing] -> pass (J2)
  • iter::adapters::array_chunks::test_iterator_array_chunks_try_fold: [missing] -> pass (J2)
  • mpsc::smoke_port_gone: [missing] -> pass (J2)
  • mpsc_sync::recv_a_lot: [missing] -> pass (J2)
  • mpsc_sync::shared_chan_stress: [missing] -> pass (J2)
  • num::ops::test_add_defined: [missing] -> pass (J2)
  • result::test_unwrap_unchecked: [missing] -> pass (J2)
  • slice::split_off_first_mut_nonempty: [missing] -> pass (J2)
  • slice::test_array_chunks_mut_count: [missing] -> pass (J2)
  • str::slice_index::range_neg_width::index_mut_fail: [missing] -> pass (J2)
  • string::test_extend_ref: [missing] -> pass (J2)
  • sys_common::wtf8::tests::unwobbly_wtf8_plus_utf8_is_utf8: [missing] -> pass (J2)
  • time::div_duration_f64: [missing] -> pass (J2)
  • vec::max_dont_panic: [missing] -> pass (J2)
  • binary_heap::bench_from_vec: [missing] -> pass (J3)
  • iter::bench_max_by_key2: [missing] -> pass (J3)
  • net::udp::tests::udp_clone_two_write: [missing] -> pass (J3)
  • num::int_sqrt::u128_sqrt_predictable: [missing] -> pass (J3)
  • os::unix::net::tests::test_unix_datagram_connect_to_recv_addr: [missing] -> pass (J3)
  • sort::tests::stable::deterministic_i32_saw_mixed: [missing] -> pass (J3)
  • sort::tests::unstable::self_cmp_cell_i32_random_s95: [missing] -> pass (J3)
  • str::bench_contains_32b_in_long: [missing] -> pass (J3)
  • str::char_count::en_small::case02_iter_increment: [missing] -> pass (J3)
  • str::ends_with_unichar::short_pile_of_poo: [missing] -> pass (J3)
  • str::rfind_zzz_char::short_ascii: [missing] -> pass (J3)
  • str::split_a_str::short_ascii: [missing] -> pass (J3)
  • tests::test_error_on_exceed: [missing] -> pass (J3)

Stage 2

  • bit_set::tests::test_new_filled: pass -> [missing] (J0)
  • clean::types::tests::should_unindent: pass -> [missing] (J0)
  • errors::verify_codegen_ssa_out_of_range_integer_27: pass -> [missing] (J0)
  • errors::verify_parse_expect_eq_instead_of_eqeq_17: pass -> [missing] (J0)
  • errors::verify_parse_multiple_where_clauses_97: pass -> [missing] (J0)
  • errors::verify_passes_coroutine_on_non_closure_89: pass -> [missing] (J0)
  • errors::verify_passes_no_link_61: pass -> [missing] (J0)
  • html::render::write_shared::tests::read_template_test: pass -> [missing] (J0)
  • interval::tests::contains: pass -> [missing] (J0)
  • lints::verify_lint_confusable_identifier_pair_75: pass -> [missing] (J0)
  • lints::verify_lint_reserved_multihash_151: pass -> [missing] (J0)
  • lints::verify_lint_unknown_macro_variable_122: pass -> [missing] (J0)
  • lints::verify_lint_unused_closure_94: pass -> [missing] (J0)
  • markdown::parse::tests::test_parse_code_block: pass -> [missing] (J0)
  • tests::format_open_brace_tab: pass -> [missing] (J0)
  • sort::tests::stable::violate_ord_retain_orig_set_string_random_d20: ignore -> [missing] (J1)
  • string::test_try_with_capacity: ignore -> [missing] (J1)
  • c_str2::c_string_from_empty_string: pass -> [missing] (J2)
  • char::eu_iterator_specializations: pass -> [missing] (J2)
  • collections::btree::map::tests::test_extract_if::height_0_removing_all: pass -> [missing] (J2)
  • floats::f32::test_round: pass -> [missing] (J2)
  • floats::f64::test_neg_zero: pass -> [missing] (J2)
  • hash::test_writer_hasher: pass -> [missing] (J2)
  • io::buffered::tests::test_buffered_reader_stream_position: pass -> [missing] (J2)
  • io::stdio::tests::test_lock_stdin: pass -> [missing] (J2)
  • iter::adapters::copied::test_copied: pass -> [missing] (J2)
  • iter::range::test_range_step: pass -> [missing] (J2)
  • mpsc_sync::send3: pass -> [missing] (J2)
  • mpsc_sync::smoke_chan_gone: pass -> [missing] (J2)
  • net::socket_addr::is_v6: pass -> [missing] (J2)
  • num::i128::test_div_ceil: pass -> [missing] (J2)
  • num::test_try_u16i32: pass -> [missing] (J2)
  • num::u64::test_count_ones: pass -> [missing] (J2)
  • num::u64::test_next_multiple_of: pass -> [missing] (J2)
  • pin_macro::basic: pass -> [missing] (J2)
  • reentrant_lock::trylock_works: pass -> [missing] (J2)
  • since_epoch: pass -> [missing] (J2)
  • slice::split_as_slice: pass -> [missing] (J2)
  • slice::split_off_first_mut_nonempty: pass -> [missing] (J2)
  • slice::split_off_mut_in_bounds_range_to: pass -> [missing] (J2)
  • slice::split_off_mut_oob_range_to_inclusive: pass -> [missing] (J2)
  • str::pattern::str_searcher_ascii_haystack_seq::bwd: pass -> [missing] (J2)
  • str::test_replacen: pass -> [missing] (J2)
  • str::test_split_char_iterator: pass -> [missing] (J2)
  • string::test_from_str: pass -> [missing] (J2)
  • test_components_debug: pass -> [missing] (J2)
  • thin_box::align1small: pass -> [missing] (J2)
  • vec::extract_if_true: pass -> [missing] (J2)
  • vec::test_extend_from_within_empty_vec: pass -> [missing] (J2)
  • btree::set::intersection_random_10k_vs_10k: pass -> [missing] (J3)
  • fs::tests::dir_entry_methods: pass -> [missing] (J3)
  • fs::tests::recursive_mkdir_dot: pass -> [missing] (J3)
  • net::addr_parser::bench_parse_ipv4: pass -> [missing] (J3)
  • num::dec2flt::bench_pi_short: pass -> [missing] (J3)
  • os::unix::fs::tests::write_vectored_at: pass -> [missing] (J3)
  • slice::rotate_huge_by1234577_u64: pass -> [missing] (J3)
  • sort::tests::stable::correct_u64_saw_mixed: pass -> [missing] (J3)
  • stats::tests::test_sum_f64s: pass -> [missing] (J3)
  • vec::bench_extend_from_slice_0100_0100: pass -> [missing] (J3)

(and 16608 additional test diffs)

Additionally, 16713 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard ec28ae9454139023117270985f114823d6570657 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-2: 1171.8s -> 5134.3s (338.2%)
  2. test-various: 2233.1s -> 4141.7s (85.5%)
  3. x86_64-gnu-aux: 3723.5s -> 5675.2s (52.4%)
  4. dist-x86_64-apple: 10632.6s -> 7677.4s (-27.8%)
  5. aarch64-apple: 5888.1s -> 5129.2s (-12.9%)
  6. x86_64-gnu-llvm-20-2: 7152.8s -> 6245.2s (-12.7%)
  7. x86_64-apple-1: 7365.8s -> 8282.7s (12.4%)
  8. dist-aarch64-apple: 4675.9s -> 5159.1s (10.3%)
  9. dist-aarch64-linux: 8041.2s -> 7561.4s (-6.0%)
  10. x86_64-gnu-debug: 5986.7s -> 6280.4s (4.9%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ec28ae9): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
-1.0% [-10.6%, -0.2%] 67
Improvements ✅
(secondary)
-0.5% [-1.2%, -0.2%] 59
All ❌✅ (primary) -1.0% [-10.6%, -0.2%] 67

Max RSS (memory usage)

Results (primary -3.6%, secondary 1.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.6% [1.6%, 1.6%] 1
Regressions ❌
(secondary)
1.6% [0.4%, 4.8%] 10
Improvements ✅
(primary)
-5.4% [-8.5%, -1.7%] 3
Improvements ✅
(secondary)
-0.9% [-1.2%, -0.6%] 3
All ❌✅ (primary) -3.6% [-8.5%, 1.6%] 4

Cycles

Results (primary -5.0%, secondary -0.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.1% [0.5%, 1.8%] 8
Improvements ✅
(primary)
-5.0% [-11.0%, -0.6%] 7
Improvements ✅
(secondary)
-1.3% [-5.3%, -0.5%] 11
All ❌✅ (primary) -5.0% [-11.0%, -0.6%] 7

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 778.793s -> 776.684s (-0.27%)
Artifact size: 370.46 MiB -> 370.33 MiB (-0.03%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants