Skip to content

Improve performance and resource management#4

Merged
rjrodger merged 4 commits intomainfrom
claude/analyze-performance-issues-a37Vu
Mar 24, 2026
Merged

Improve performance and resource management#4
rjrodger merged 4 commits intomainfrom
claude/analyze-performance-issues-a37Vu

Conversation

@rjrodger
Copy link
Copy Markdown
Contributor

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

  • Added canonPaths Set: Replaced O(n) linear search with O(1) Set lookup when checking if a path has already been added to the canons array
  • Fixed interval memory leak: Store the intervalId returned by setInterval() and properly clear it in the stop() method to prevent intervals from running after the watch is stopped
  • Refactored update() method: Converted reduce-based file collection to a simpler for-loop for better readability
  • Fixed async iteration: Changed forEach with async/await to a proper for...of loop to ensure sequential execution

Model class optimizations

  • Added debug level check: Wrap expensive debug logging (JSON serialization and string manipulation) behind isLevelEnabled('debug') check to avoid unnecessary computation when debug logging is disabled
  • Fixed array iteration: Changed .map() to .forEach() for side-effect-only operations on watchmap keys

Local producer optimization

  • Extracted regex constant: Moved inline regex /\s*,+\s*/ to a module-level constant ORDERING_SPLIT_RE to avoid recreating the regex on every function call

Code quality fixes

  • Fixed typo: "aleady" → "already" in comment

Notable Implementation Details

  • The canonPaths Set is kept in sync with the canons array, maintaining both for backward compatibility while improving lookup performance
  • The interval cleanup in stop() prevents resource leaks in long-running applications or test suites
  • The regex extraction is a micro-optimization that reduces garbage collection pressure in the producer loop

https://claude.ai/code/session_01PDhvzBbiEYKozpEPui3vAJ

claude added 4 commits March 24, 2026 14:11
- 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
@rjrodger rjrodger merged commit a14f87e into main Mar 24, 2026
3 checks passed
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.

2 participants