Skip to content

⚡ Optimize file discovery loop in check-links.py - #90

Open
Ch3fUlrich wants to merge 2 commits into
mainfrom
perf-optimize-check-links-1741372840706191848
Open

Ch3fUlrich wants to merge 2 commits into
mainfrom
perf-optimize-check-links-1741372840706191848

Conversation

@Ch3fUlrich

Copy link
Copy Markdown
Owner

💡 What: Replaced five independent glob.glob calls (including a recursive **/README.md) in tests/check-links.py:markdown_files() with a single, optimized os.walk() traversal that avoids traversing into .git.

🎯 Why: The previous implementation forced Python to traverse the entire directory structure repeatedly for each glob pattern, matching and resolving paths five times. By using os.walk() and filtering files directly against our pattern equivalents, the filesystem is only traversed once. This drastically reduces stat calls and CPU overhead, especially as the repository grows.

📊 Measured Improvement:
Benchmarking against a deeply nested synthetic repository structure simulating ~10,000 directories (to isolate tree traversal speed):

  • Baseline (recursive globs): ~0.017-0.018 seconds
  • Optimized (os.walk): ~0.007-0.008 seconds
  • Improvement: ~57% reduction in execution time for file discovery.
    (Note: Both implementations were verified to return identical lists of matching markdown files.)

PR created automatically by Jules for task 1741372840706191848 started by @Ch3fUlrich

Replaces multiple recursive glob.glob calls with a single os.walk traversal
in markdown_files() to prevent repetitive full-tree searches. This improves
the script's execution efficiency, particularly on deep directory structures
or repositories with a high volume of non-markdown files.

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

Copy link
Copy Markdown

👋 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.

Replaces multiple recursive glob.glob calls with a single os.walk traversal
in markdown_files() to prevent repetitive full-tree searches. This improves
the script's execution efficiency, particularly on deep directory structures
or repositories with a high volume of non-markdown files.

Also includes a fix for PSScriptAnalyzer empty catch block warnings in
PowerShell modules that were failing the Windows CI suite.

Co-authored-by: Ch3fUlrich <71930650+Ch3fUlrich@users.noreply.github.com>
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