mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Rollup merge of #163126 - charliermarsh:charlie/conflicts, r=oli-obk
Skip redundant storage-conflict updates during coroutine layout
## Summary
When computing coroutine storage conflicts, we currently record conflicts between every pair in the live set. This PR instead remembers the last live set whose conflicts were recorded; if the current set is a subset, we skip the matrix updates. For example, after recording `{a, b, c}`, observing `{a, b}` adds no new conflicts.
I used an LLM to profile this change, and saw a compiler CPU reduction in the following projects:
- Codex: 2.69%
- Ruff: 2.84%
- uv: 5.28%
- ty: 3.28%
This commit is contained in:
@@ -253,6 +253,7 @@ fn compute_storage_conflicts<'mir, 'tcx>(
|
||||
saved_locals,
|
||||
local_conflicts: BitMatrix::from_row_n(&ineligible_locals, body.local_decls.len()),
|
||||
eligible_storage_live: DenseBitSet::new_empty(body.local_decls.len()),
|
||||
last_recorded_storage_live: DenseBitSet::new_empty(body.local_decls.len()),
|
||||
};
|
||||
|
||||
// Filter out:
|
||||
@@ -297,6 +298,10 @@ struct StorageConflictVisitor<'a> {
|
||||
local_conflicts: BitMatrix<Local, Local>,
|
||||
// We keep this bitset as a buffer to avoid reallocating memory.
|
||||
eligible_storage_live: DenseBitSet<Local>,
|
||||
// The last live set whose conflicts were recorded. This is just a fast path:
|
||||
// if the current live set is a subset, we can skip updating the conflict matrix
|
||||
// since its conflicts have already been recorded.
|
||||
last_recorded_storage_live: DenseBitSet<Local>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> ResultsVisitor<'tcx, MaybeRequiresStorage> for StorageConflictVisitor<'a> {
|
||||
@@ -324,9 +329,14 @@ impl StorageConflictVisitor<'_> {
|
||||
self.eligible_storage_live.clone_from(state);
|
||||
self.eligible_storage_live.intersect(&**self.saved_locals);
|
||||
|
||||
if self.last_recorded_storage_live.superset(&self.eligible_storage_live) {
|
||||
return;
|
||||
}
|
||||
|
||||
for local in self.eligible_storage_live.iter() {
|
||||
self.local_conflicts.union_row_with(&self.eligible_storage_live, local);
|
||||
}
|
||||
std::mem::swap(&mut self.last_recorded_storage_live, &mut self.eligible_storage_live);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user