Optimize slow code paths in AI service, database, and React components - #2
Draft
WilliamsMiao with Copilot wants to merge 3 commits into
Draft
Optimize slow code paths in AI service, database, and React components#2WilliamsMiao with Copilot wants to merge 3 commits into
WilliamsMiao with Copilot wants to merge 3 commits into
Conversation
Backend optimizations: - AIService: Optimize checkDynamicEventTrigger with cached lowercase keywords and early filtering - RequestQueue: Replace O(n) linear search with O(log n) binary search for priority queue insertion - MemoryManager: Single-pass sentence processing with Set-based keyword lookup - database: Batch deletions with transactions and Promise.all for parallel operations Frontend optimizations: - StoryPanel: Memoize displayMessages filtering with useMemo - StoryPanel: Memoize formatTimestamp with useCallback - StoryPanel: Pre-compile static NPC regex pattern Co-authored-by: WilliamsMiao <181537281+WilliamsMiao@users.noreply.github.com>
- Remove unnecessary .slice() calls in StoryPanel.jsx displayMessages memoization - Remove unused 'emotion' pattern from MemoryManager patterns - Use WeakMap for keyword caching in AIService to avoid mutating external objects Co-authored-by: WilliamsMiao <181537281+WilliamsMiao@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Identify and suggest improvements for slow code
Optimize slow code paths in AI service, database, and React components
Dec 1, 2025
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.
Performance audit identified several inefficient patterns: O(n) priority queue insertion, repeated toLowerCase() calls in hot paths, sequential awaits where parallelism is possible, and missing React memoization.
Backend
AIService.js: Cache lowercase keywords in WeakMap instead of mutating trigger objects. Pre-filter events by chapter range before iteration.
RequestQueue.js: Replace O(n) linear search with O(log n) binary search for priority queue insertion.
MemoryManager.js: Single-pass sentence processing with Set-based keyword lookup. Remove unused emotion pattern.
database.js: Wrap
deleteStoryin transaction, parallelize independent deletions withPromise.all.Frontend
displayMessagesfiltering withuseMemoformatTimestampwithuseCallbacklastIndexbefore iterationOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.