Code quality enhancement Part 2.3 #11

Closed
opened 2026-07-12 12:03:33 +00:00 by Pakobbix · 2 comments
Owner

I asked an AI to review Code Quality.

This is part 2.3 for the enhancement:

2.3 Memory Management

Current state: DOM element references are cached as jQuery objects in state.js.

Optimization opportunities:

  • jQuery object cache invalidation: When the panel is destroyed/rebuilt, cached jQuery references become stale. Add a cache invalidation mechanism.
  • Event listener cleanup: The unregisterAllEvents() function exists but should be verified to clean up all listeners, including those registered in sub-modules.
  • Debug log memory: debugLogs array in state.js is capped at 100 entries — good. But consider if it should be cleared on chat change.
I asked an AI to review Code Quality. This is part 2.3 for the enhancement: ### 2.3 Memory Management Current state: DOM element references are cached as jQuery objects in state.js. **Optimization opportunities:** - jQuery object cache invalidation: When the panel is destroyed/rebuilt, cached jQuery references become stale. Add a cache invalidation mechanism. - Event listener cleanup: The unregisterAllEvents() function exists but should be verified to clean up all listeners, including those registered in sub-modules. - Debug log memory: debugLogs array in state.js is capped at 100 entries — good. But consider if it should be cleared on chat change.
ARIA self-assigned this 2026-07-12 12:05:08 +00:00
ARIA added the enhancement label 2026-07-12 12:05:08 +00:00
Collaborator

I'll work on this. Give me a moment to inspect the codebase and prepare a fix.

I'll work on this. Give me a moment to inspect the codebase and prepare a fix.
Collaborator

All memory management optimizations implemented:

jQuery cache invalidation: clearDomCache() clears all cached jQuery references on panel rebuild
Event listener cleanup: All on()/once() handlers now tracked for cleanup by unregisterAllEvents()
Debug log memory: clearDebugLogs() called on CHAT_CHANGED to prevent accumulation
jQuery cleanup infrastructure: trackJQueryHandler()/cleanupJQueryEvents() ready for use

Tests: 25/25 passed (14 new memory management tests).

PR: #12

All memory management optimizations implemented: ✅ jQuery cache invalidation: clearDomCache() clears all cached jQuery references on panel rebuild ✅ Event listener cleanup: All on()/once() handlers now tracked for cleanup by unregisterAllEvents() ✅ Debug log memory: clearDebugLogs() called on CHAT_CHANGED to prevent accumulation ✅ jQuery cleanup infrastructure: trackJQueryHandler()/cleanupJQueryEvents() ready for use Tests: 25/25 passed (14 new memory management tests). PR: https://gitea.zephyre.one/Pakobbix/rpg-companion-sillytavern/pulls/12
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Pakobbix/rpg-companion-sillytavern#11