Skip to content

⚡ Bolt: Replace path().is_file() with file_type().is_some_and(|ft| ft.is_file())#583

Open
mudcube wants to merge 1 commit into
mainfrom
bolt-optimize-stat-calls-directory-traversal-9603200225256109730
Open

⚡ Bolt: Replace path().is_file() with file_type().is_some_and(|ft| ft.is_file())#583
mudcube wants to merge 1 commit into
mainfrom
bolt-optimize-stat-calls-directory-traversal-9603200225256109730

Conversation

@mudcube

@mudcube mudcube commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

💡 What: Replacing .path().is_file() with .file_type().is_some_and(|ft| ft.is_file()) when traversing directories using ignore or walkdir.
🎯 Why: Avoids unnecessary stat syscalls during directory traversal because metadata is already retrieved during readdir.
📊 Impact: Faster directory walking when filtering files.
🔬 Measurement: Observe faster performance during workspace operations involving bulk file discovery.


PR created automatically by Jules for task 9603200225256109730 started by @mudcube

….is_file())

When traversing directories using crates like `ignore`, the metadata (including file type) is retrieved efficiently during the `readdir` operation. Calling `entry.path().is_file()` results in an unnecessary `stat` system call to check if it's a file, drastically slowing down recursive directory scans.
By replacing `.path().is_file()` with `.file_type().is_some_and(|ft| ft.is_file())` in all the workspace `WalkBuilder` instances, we utilize the already cached metadata, significantly improving performance when discovering source files across large directories.

Co-authored-by: mudcube <101564+mudcube@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying typemill with  Cloudflare Pages  Cloudflare Pages

Latest commit: 192ac45
Status: ✅  Deploy successful!
Preview URL: https://dc526a99.typemill.pages.dev
Branch Preview URL: https://bolt-optimize-stat-calls-dir.typemill.pages.dev

View logs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 192ac45083

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let path = entry.path();
if path.is_file() {
// ⚡ Bolt: Use entry.file_type() to avoid unnecessary stat syscalls
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 during scans

When the workspace contains a symlink to a source file, this changes behavior: Path::is_file() follows the symlink and previously included it, while DirEntry::file_type() reports the directory entry itself and returns a symlink file type when WalkBuilder is not configured with follow_links(true). As a result, symlinked project files are now skipped by import scanning, so imports in those files will not be updated; the same replacement appears in the other changed walkers as well. Consider using entry.file_type().is_some_and(|ft| ft.is_file()) || entry.path().is_file() (or explicitly following links) if symlinked files should remain supported.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant