Skip to content

perf: optimize watchdog hot path attribute access and string slicing#131

Open
shenald-dev wants to merge 4 commits into
mainfrom
jules/bolt-optimize-getattr-string-slicing-9213988737496969751
Open

perf: optimize watchdog hot path attribute access and string slicing#131
shenald-dev wants to merge 4 commits into
mainfrom
jules/bolt-optimize-getattr-string-slicing-9213988737496969751

Conversation

@shenald-dev
Copy link
Copy Markdown
Owner

Identified and applied minor CPU performance improvements to the watchdog file watcher on_any_event and _is_ignored_impl hot paths. By pre-computing path length integers during class initialization and preferring direct attribute access over getattr for watchdog guaranteed attributes (src_path, event_type), the execution overhead of high-frequency background events is reduced. Validated by comprehensive test suite and linters. Added learning into the .jules/bolt.md journal.


PR created automatically by Jules for task 9213988737496969751 started by @shenald-dev

Pre-computes path lengths to avoid redundant `len()` calls on immutable strings in loops,
and replaces `getattr` with direct attribute access for guaranteed attributes (`src_path`, `event_type`)
on watchdog FileSystemEvent objects to reduce function call overhead in high-frequency event loops.

Co-authored-by: shenald-dev <245350826+shenald-dev@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.

@shenald-dev
Copy link
Copy Markdown
Owner Author

@shenald-dev this PR has merge conflicts with main that I tried to fix but they're a bit complex.

To resolve manually:

git checkout jules/bolt-optimize-getattr-string-slicing-9213988737496969751
git fetch origin && git merge origin/main
# resolve conflicts, then commit and push

Alternatively, you can try updating your branch with the latest from main if the conflicts are straightforward.

@shenald-dev shenald-dev added enhancement New feature or request refactor labels May 20, 2026
@shenald-dev
Copy link
Copy Markdown
Owner Author

The performance tweaks look sensible and are well-scoped. Please resolve the merge conflicts with main before merging. Consider adding a brief comment in the code explaining why direct attribute access is safe (guaranteed by watchdog). After conflicts are resolved, this PR is ready to merge.

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev this PR has merge conflicts with main that I tried to fix but they're a bit complex.

To resolve manually:

git checkout jules/bolt-optimize-getattr-string-slicing-9213988737496969751
git fetch origin && git merge origin/main
# resolve conflicts, then commit and push

Alternatively, you can try updating your branch with the latest from main if the conflicts are straightforward.

I have successfully resolved the merge conflicts with main and updated the branch.

Pre-computes path lengths to avoid redundant `len()` calls on immutable strings in loops,
and replaces `getattr` with direct attribute access for guaranteed attributes (`src_path`, `event_type`)
on watchdog FileSystemEvent objects to reduce function call overhead in high-frequency event loops.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
@shenald-dev
Copy link
Copy Markdown
Owner Author

🔄 Re-evaluating based on recent changes:

The performance optimizations are sensible and well-scoped. However, the PR currently has merge conflicts with main that must be resolved before merging. After resolving conflicts, consider adding a brief inline comment explaining why direct attribute access is safe (guaranteed by watchdog). Once conflicts are fixed, this PR is ready to merge.

Reviewed — quality: medium

@google-labs-jules
Copy link
Copy Markdown
Contributor

🔄 Re-evaluating based on recent changes:

The performance optimizations are sensible and well-scoped. However, the PR currently has merge conflicts with main that must be resolved before merging. After resolving conflicts, consider adding a brief inline comment explaining why direct attribute access is safe (guaranteed by watchdog). Once conflicts are fixed, this PR is ready to merge.

Reviewed — quality: medium

I have added an inline comment explaining that event_type and src_path are guaranteed by watchdog's FileSystemEvent. The merge conflicts were resolved previously.

Pre-computes path lengths to avoid redundant `len()` calls on immutable strings in loops,
and replaces `getattr` with direct attribute access for guaranteed attributes (`src_path`, `event_type`)
on watchdog FileSystemEvent objects to reduce function call overhead in high-frequency event loops.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
@shenald-dev
Copy link
Copy Markdown
Owner Author

🔄 Re-evaluating based on recent changes:

The performance improvements are sensible and well-scoped. Please resolve the merge conflicts with main before merging. After resolving conflicts, consider adding a brief inline comment explaining why direct attribute access is safe (guaranteed by watchdog).

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

🔄 Re-evaluating based on recent changes:

The performance improvements are sensible and well-scoped. Please resolve the merge conflicts with main before merging. After resolving conflicts, consider adding a brief inline comment explaining why direct attribute access is safe (guaranteed by watchdog).

Reviewed — quality: high

I have successfully resolved the merge conflicts with main and added the requested inline comment explaining why direct attribute access is safe for event_type and src_path.

Pre-computes path lengths to avoid redundant `len()` calls on immutable strings in loops,
and replaces `getattr` with direct attribute access for guaranteed attributes (`src_path`, `event_type`)
on watchdog FileSystemEvent objects to reduce function call overhead in high-frequency event loops.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant