Skip to content

Commit e1ef00d

Browse files
committed
perf: use IdentityHasher for visited set to avoid double hashing (#837)
## Summary - Replace `FxHashSet<u64>` with `HashSet<u64, BuildHasherDefault<IdentityHasher>>` for the visited set in canonicalization - Avoids double hashing since the stored values are already hash values (`u64`) - Consistent with the existing usage of `IdentityHasher` for `HashSet<CachedPath>` in the same file ## Test plan - ✅ All existing tests pass (`cargo test --lib`) - ✅ No clippy warnings (`cargo clippy --all-targets -- --deny warnings`) - ✅ Code compiles successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 5a42e31 commit e1ef00d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/cache/cache_impl.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ impl<Fs: FileSystem> Cache<Fs> {
230230
// The Result is stored inside the OnceLock to cache both success and failure cases.
231231
let result = path.canonicalized.get_or_init(|| {
232232
// Each canonicalization chain gets its own visited set for circular symlink detection
233-
let mut visited = StdHashSet::new();
233+
let mut visited =
234+
StdHashSet::with_hasher(BuildHasherDefault::<IdentityHasher>::default());
234235
self.canonicalize_with_visited(path, &mut visited).map(|cp| Arc::downgrade(&cp.0))
235236
});
236237

@@ -252,7 +253,7 @@ impl<Fs: FileSystem> Cache<Fs> {
252253
fn canonicalize_with_visited(
253254
&self,
254255
path: &CachedPath,
255-
visited: &mut StdHashSet<u64>,
256+
visited: &mut StdHashSet<u64, BuildHasherDefault<IdentityHasher>>,
256257
) -> Result<CachedPath, ResolveError> {
257258
// Check for circular symlink by tracking visited paths in the current canonicalization chain
258259
if !visited.insert(path.hash) {

0 commit comments

Comments
 (0)