Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
## 2025-05-19 - File Discovery Allocations
**Learning:** In `discover_importing_files`, `WalkBuilder` results were being converted to `PathBuf` via `.map(|e| e.into_path())` *before* filtering. This caused allocations for every single file in the workspace (including excluded files and directories).
**Action:** Filter `ignore::DirEntry` directly using `entry.file_type()` and `entry.path()` before mapping to `PathBuf`. This avoids allocations for non-matching files.

## 2025-10-24 - Directory Traversal is_file()
**Learning:** When using directory traversal crates like `ignore` or `walkdir` in Rust, calling `entry.path().is_file()` on directory entries performs an unnecessary `stat` syscall. Using `entry.file_type().is_some_and(|ft| ft.is_file())` utilizes the metadata already retrieved during the `readdir` operation, significantly improving performance.
**Action:** Avoid calling `entry.path().is_file()` on `DirEntry` values from traversal libraries. Use `entry.file_type().is_some_and(|ft| ft.is_file())` instead.
4 changes: 3 additions & 1 deletion crates/mill-handlers/src/handlers/common/checksums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ pub async fn calculate_checksums_for_directory_rename(
.build();

for entry in walker.flatten() {
if entry.path().is_file() {
// Avoid `entry.path().is_file()` to prevent unnecessary `stat` syscalls,
// relying on the cached metadata from the `readdir` operation.
if entry.file_type().is_some_and(|ft| ft.is_file()) {
if let Ok(content) = context.app_state.file_service.read_file(entry.path()).await {
file_checksums.insert(
entry.path().to_string_lossy().to_string(),
Expand Down
4 changes: 3 additions & 1 deletion crates/mill-handlers/src/handlers/prune_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ impl PrunePlanner {
let walker = ignore::WalkBuilder::new(&abs_dir).hidden(false).build();
let files = walker
.flatten()
.filter(|entry| entry.path().is_file())
// Avoid `entry.path().is_file()` to prevent unnecessary `stat` syscalls,
// relying on the cached metadata from the `readdir` operation.
.filter(|entry| entry.file_type().is_some_and(|ft| ft.is_file()))
.map(|entry| entry.path().to_path_buf())
.collect();
Ok((files, abs_dir))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ impl RenameService {
let mut files_to_move = 0;
let walker = ignore::WalkBuilder::new(&old_path).hidden(false).build();
for entry in walker.flatten() {
if entry.path().is_file() {
// Avoid `entry.path().is_file()` to prevent unnecessary `stat` syscalls,
// relying on the cached metadata from the `readdir` operation.
if entry.file_type().is_some_and(|ft| ft.is_file()) {
files_to_move += 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ impl FileService {
let mut files = Vec::new();
let walker = ignore::WalkBuilder::new(dir).hidden(false).build();
for entry in walker.flatten() {
if entry.path().is_file() {
// Avoid `entry.path().is_file()` to prevent unnecessary `stat` syscalls,
// relying on the cached metadata from the `readdir` operation.
if entry.file_type().is_some_and(|ft| ft.is_file()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve symlinked files in directory traversals

When the directory contains a symlink that resolves to a regular file, this replacement is not equivalent to the old check: Path::is_file() follows the link, but with the default WalkBuilder settings entry.file_type() reports the directory entry itself as a symlink, so the path is dropped from files_to_move. The directory rename still moves that symlink, so preview/result counts and detailed file lists under-report what was moved; the same filter pattern in the checksum/delete planners also stops checksumming these paths.

Useful? React with πŸ‘Β / πŸ‘Ž.

files.push(entry.path().to_path_buf());
}
}
Expand Down
Loading