This repository was archived by the owner on Aug 1, 2025. It is now read-only.
Add additional memoization to different UI levels - #8184
Closed
vovakulikov wants to merge 4 commits into
Closed
Conversation
pkukielka
reviewed
Jul 21, 2025
fkling
reviewed
Jul 21, 2025
Comment on lines
+192
to
+208
| export function memoize<T extends (...args: any[]) => any>( | ||
| func: T | ||
| ): (...args: Parameters<T>) => ReturnType<T> { | ||
| let lastArguments: any[] | null = null | ||
| let lastCalculatedValue: ReturnType<T> | null = null | ||
|
|
||
| return (...args: Parameters<T>): ReturnType<T> => { | ||
| if (isEqual(lastArguments, args)) { | ||
| return lastCalculatedValue as ReturnType<T> | ||
| } | ||
|
|
||
| lastArguments = args | ||
| lastCalculatedValue = func(args) | ||
|
|
||
| return lastCalculatedValue as ReturnType<T> | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
I think lodash has a memoize function as well... does that not work for our purposes?
Contributor
Author
There was a problem hiding this comment.
Yes, it does have memoize function, but this function gathers all arguments in key-value cache store, which will produce another place which GC can free up, so I remember only the last result
pkukielka
reviewed
Jul 21, 2025
Contributor
There was a problem hiding this comment.
FWIW I tested this the same way as I tested my branch: https://github.com/sourcegraph/cody/pull/8183
and I get exactly the same (improved vs main) results
For me this does not fix the memory leak but makes an app much quicker.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR adds memoisation to different UI components to avoid unnecessary react renders (potentially it should improve memory allocation during LLM responses on the chat client)
Test plan