-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve VecCache under parallel frontend
This replaces the single Vec allocation with a series of progressively larger buckets. With the cfg for parallel enabled but with -Zthreads=1, this looks like a slight regression in i-count and cycle counts (<0.1%). With the parallel frontend at -Zthreads=4, this is an improvement (-5% wall-time from 5.788 to 5.4688 on libcore) than our current Lock-based approach, likely due to reducing the bouncing of the cache line holding the lock. At -Zthreads=32 it's a huge improvement (-46%: 8.829 -> 4.7319 seconds).
- Loading branch information
1 parent
1d1356d
commit f73ad9b
Showing
3 changed files
with
277 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use super::*; | ||
|
||
#[test] | ||
fn vec_cache_empty() { | ||
let cache: VecCache<u32, u32> = VecCache::default(); | ||
for key in 0..=u32::MAX { | ||
assert!(cache.lookup(&key).is_none()); | ||
} | ||
} | ||
|
||
#[test] | ||
fn vec_cache_insert_and_check() { | ||
let cache: VecCache<u32, u32> = VecCache::default(); | ||
cache.complete(0, 1, DepNodeIndex::ZERO); | ||
assert_eq!(cache.lookup(&0), Some((1, DepNodeIndex::ZERO))); | ||
} | ||
|
||
#[test] | ||
fn slot_index_exhaustive() { | ||
let mut buckets = [0u32; 21]; | ||
for idx in 0..=u32::MAX { | ||
buckets[SlotIndex::from_index(idx).bucket_idx] += 1; | ||
} | ||
let mut prev = None::<SlotIndex>; | ||
for idx in 0..u32::MAX { | ||
let slot_idx = SlotIndex::from_index(idx); | ||
if let Some(p) = prev { | ||
if p.bucket_idx == slot_idx.bucket_idx { | ||
assert_eq!(p.index_in_bucket + 1, slot_idx.index_in_bucket); | ||
} else { | ||
assert_eq!(slot_idx.index_in_bucket, 0); | ||
} | ||
} else { | ||
assert_eq!(idx, 0); | ||
assert_eq!(slot_idx.index_in_bucket, 0); | ||
assert_eq!(slot_idx.bucket_idx, 0); | ||
} | ||
|
||
assert_eq!(buckets[slot_idx.bucket_idx], slot_idx.entries as u32); | ||
|
||
prev = Some(slot_idx); | ||
} | ||
} |