perf: optimize hot paths in file watcher#123
Conversation
- Replaced `getattr(event, 'event_type')` with direct attribute access `event.event_type`. - Pre-computed `_abs_base_path` and `_base_prefix` string lengths during initialization to avoid repeated `len()` calls in the fast-path string slicing. - Hoisted loop-invariant `match = regex.match` method lookups outside of iterative paths. - Removed flawed `self.current_process is process` guard in the `process.wait()` evaluation block, which could cause process termination logs to go dead if a rapid reload overwrote the class property before the previous wait block completed. Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Hey @shenald-dev, heads up — this PR has merge conflicts with To fix: |
|
The performance optimizations look sound and are well-justified. CI is passing. Please resolve the merge conflicts with main (e.g., by rebasing or merging origin/main) before proceeding to merge. Reviewed — quality: high |
I have successfully fetched the latest |
Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
On this run, several hot paths inside the file watcher's event evaluation logic were identified and optimized to eliminate unnecessary computational overhead and string operations.
Improvements Made
getattrwith direct property access (event.event_typeandevent.src_path), as these properties are guaranteed by thewatchdoglibrary. This eliminates the function call overhead ofgetattron every file system event.len(self._abs_base_path)andlen(self._base_prefix)once during object initialization instead of evaluatinglen()continuously within the_is_ignored_implstring slicing hot path.match = regex.matchlookups out of the core iteration loops when evaluating compound directory regexes.self.current_process is processvalidation guard immediately followingprocess.wait(). If a new file event triggers a process termination and restarts a new process rapidly,self.current_processis reassigned. This caused the older process to finish itswait()but silently drop its outcome evaluation because it was no longer the "current" process, resulting in missing standard output messages.Verification
vulture.pytest. All 16 tests pass seamlessly.ruff.Readiness
The repository is perfectly stable and verified. Version
v0.1.26has been successfully tagged and documented.PR created automatically by Jules for task 11990249264601560953 started by @shenald-dev