fix: memory leak and performance in Last Calls section#92
Open
edospadoni wants to merge 1 commit intomainfrom
Open
fix: memory leak and performance in Last Calls section#92edospadoni wants to merge 1 commit intomainfrom
edospadoni wants to merge 1 commit intomainfrom
Conversation
- Limit missedCalls array to 50 elements to prevent unbounded growth - Replace lodash differenceWith and array.map().includes() with Set lookups for O(1) uniqueid comparison - Add cleanup for IPC event listeners in NethLinkPage and store - Remove unnecessary array spreads on every update
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.
Problem
A customer with high call volume (~1300 calls/day, 1.8M CDR records) experiences white screen and slowdowns when NethLink stays open on the "Last calls" tab for extended periods.
Root cause analysis identified four issues:
missedCallsarray — Grows indefinitely over time without ever being truncated, consuming increasing amounts of memoryprepareCalls()runsmissedCalls.map().includes()for every call, andgestLastCalls()uses lodashdifferenceWithwith linear comparisonsNethLinkPageand 1 in the store are never removed, accumulating on every mount/unmount cycleChanges
usePhoneIslandEventHandler.ts—gestLastCalls()differenceWithwithSetfor O(1) uniqueid lookupsmissedCallsat 50 elements (oldest entries are dropped)Setfor deduplication insetMissedCallsinstead ofarray.map().includes()newLastCalls.rowsLastCallsBox.tsx—prepareCalls()missedCallIdsas aSetonce before the.map()loopmissedCalls?.map(c => c.uniqueid).includes(c.uniqueid)(O(n) per call = O(n²) total) withmissedCallIds.has(c.uniqueid)(O(1) per call = O(n) total)NethLinkPage.tsx— IPC listener cleanupuseInitialize(no cleanup) into theuseEffectwatchingaccount?.usernameremoveAllListenersfor all channelsuseInitialize(one-time, no cleanup needed)store.ts— store listener cleanupuseRegisterStoreHook'suseEffectto remove theSHARED_STATE_UPDATEDlistener and resetisRegistered