Perf: Introduce clearPreviousFieldValues for mitigation of React fiber memory issue#1392
Merged
Perf: Introduce clearPreviousFieldValues for mitigation of React fiber memory issue#1392
clearPreviousFieldValues for mitigation of React fiber memory issue#1392Conversation
clearPreviousFieldValues for mitigation or React fiber memory issue
|
readonly arrays or object.frozen arrays might throw a TypeError. but other than that this is a decent hack. |
Contributor
Author
|
never seen frozen stuff come out of DS. possible in theory, but i'll put money on it never happening in practice. |
clearPreviousFieldValues for mitigation or React fiber memory issueclearPreviousFieldValues for mitigation of React fiber memory issue
dprokop
approved these changes
Apr 2, 2026
Collaborator
dprokop
left a comment
There was a problem hiding this comment.
LGTM, but please let's get rid of feature toggles reference in scenes.
|
🚀 PR was released in |
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.
this is a
beautifulgross hack to mitigate a memory issue with React's concurrent [Fiber] reconciler, which was rolled out with React 16....in late 2017 😅while we await a final decision on facebook/react#36176, we can mostly side-step the badness of having 2x the query response data in memory at all times (previous and current). for dashboards with many and/or heavy queries this results in potentially 100MB+ of RAM savings per browser tab/dashboard.
i think this changeset is the minimal one, placed right at the entry point where panel data gets passed down through react props/state to the panel plugin components.
is this mutation risky?
in my opinion the risk is very low. relying on the previous field value arrays to stay filled with old data is nothing i have ever seen in practice. a smoke test in grafana core shows no related test failures: grafana/grafana#120190
nevertheless, this will be feature-gated behind
clearPreviousFieldValues.once this code is running in ops i will toggle it via
localstorageto smoke test some real dashboards before rolling anything out. if that feels bug-free, we can start to roll it to dev/staging/free/canary/paid etc.best case: meta fixes this misfeature in fiber
next best case: it becomes default enabled for all grafana users
worst case: it stays experimental or private preview and heavy users can opt into it
testing with single debug panel, random walk, 1,000 series * 1,440 points, multiple data refreshes:
before:
after:
📦 Published PR as canary version:
7.3.6--canary.1392.23904848795.0✨ Test out this PR locally via:
npm install @grafana/scenes@7.3.6--canary.1392.23904848795.0 npm install @grafana/scenes-react@7.3.6--canary.1392.23904848795.0 # or yarn add @grafana/scenes@7.3.6--canary.1392.23904848795.0 yarn add @grafana/scenes-react@7.3.6--canary.1392.23904848795.0