Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

fix: fix gradual memory leak / perf issue with cytoscape #56

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

skylarmb
Copy link
Contributor

Fixes the issue where the topology graph page gradually becomes laggy and increases memory usage over time. This was because the interval timer was implemented in a way that caused the graph to re-render on every execution, and there was an issue where the loading state changing in the API context caused an additional re-render. This added up to 2 re-renders per second that were not needed. Why a re-render with the same input props causes the Cytoscape library to leak memory? I am not sure, but that is beyond the scope of this as the root cause is likely deep within the Cytoscape library. The best we can do is limit renders to only happening as needed.

const stopPolling = () => {
clearInterval(timerRef.current!);
timerRef.current = null;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the TLDR of the change here is that the timer now uses a useRef instead of a useEffect, which has different behavior in regards to re-renders

@skylarmb skylarmb merged commit 703417d into main Sep 27, 2024
7 checks passed
@skylarmb skylarmb deleted the sbrown/memory-leak branch September 27, 2024 15:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants