Improve performance and resource management#4
Merged
Conversation
- Fix critical async forEach in Watch.update() that lost awaited promises, replacing with for...of loop to properly await file additions - Fix memory leak from uncleared setInterval in Watch.start() by storing interval ID and clearing it in stop() - Replace O(n) canons array lookup with O(1) Set-based path deduplication - Replace O(n²) array concat in reduce with push(...spread) for building dependency file lists - Change .map() to .forEach() where used for side effects only - Extract regex constant in local producer to avoid recompilation https://claude.ai/code/session_01PDhvzBbiEYKozpEPui3vAJ
Skip JSON.stringify, regex replace, and string operations for model-spec debug logging when debug level is not enabled. https://claude.ai/code/session_01PDhvzBbiEYKozpEPui3vAJ
- Add node 24.x to the build matrix - Update actions/checkout from v2 to v4 - Update actions/setup-node from v1 to v4 - Remove stale test22 conditional (script no longer exists) - Run coverage on node 24.x instead of 22.x https://claude.ai/code/session_01PDhvzBbiEYKozpEPui3vAJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves performance and resource management across the codebase by optimizing data structure lookups, fixing memory leaks, and reducing unnecessary computations.
Key Changes
Watch class improvements
canonPathsSet: Replaced O(n) linear search with O(1) Set lookup when checking if a path has already been added to the canons arrayintervalIdreturned bysetInterval()and properly clear it in thestop()method to prevent intervals from running after the watch is stoppedupdate()method: Converted reduce-based file collection to a simpler for-loop for better readabilityforEachwith async/await to a properfor...ofloop to ensure sequential executionModel class optimizations
isLevelEnabled('debug')check to avoid unnecessary computation when debug logging is disabled.map()to.forEach()for side-effect-only operations on watchmap keysLocal producer optimization
/\s*,+\s*/to a module-level constantORDERING_SPLIT_REto avoid recreating the regex on every function callCode quality fixes
Notable Implementation Details
canonPathsSet is kept in sync with thecanonsarray, maintaining both for backward compatibility while improving lookup performancestop()prevents resource leaks in long-running applications or test suiteshttps://claude.ai/code/session_01PDhvzBbiEYKozpEPui3vAJ