Skip to content

Perf: Introduce clearPreviousFieldValues for mitigation of React fiber memory issue#1392

Merged
leeoniya merged 5 commits intomainfrom
leeoniya/clearPreviousData
Apr 2, 2026
Merged

Perf: Introduce clearPreviousFieldValues for mitigation of React fiber memory issue#1392
leeoniya merged 5 commits intomainfrom
leeoniya/clearPreviousData

Conversation

@leeoniya
Copy link
Copy Markdown
Contributor

@leeoniya leeoniya commented Mar 12, 2026

this is a beautiful gross 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 localstorage to 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:

image

after:

image
📦 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

@leeoniya leeoniya added release Create a release when this pr is merged patch Increment the patch version when merged labels Mar 12, 2026
@leeoniya leeoniya requested review from dprokop and torkelo April 1, 2026 20:31
@leeoniya leeoniya changed the title leon perf test Perf: Introduce clearPreviousFieldValues for mitigation or React fiber memory issue Apr 1, 2026
@clord
Copy link
Copy Markdown

clord commented Apr 1, 2026

readonly arrays or object.frozen arrays might throw a TypeError. but other than that this is a decent hack.

@leeoniya
Copy link
Copy Markdown
Contributor Author

leeoniya commented Apr 1, 2026

never seen frozen stuff come out of DS. possible in theory, but i'll put money on it never happening in practice.

@leeoniya leeoniya marked this pull request as ready for review April 2, 2026 02:47
@leeoniya leeoniya changed the title Perf: Introduce clearPreviousFieldValues for mitigation or React fiber memory issue Perf: Introduce clearPreviousFieldValues for mitigation of React fiber memory issue Apr 2, 2026
Copy link
Copy Markdown
Collaborator

@dprokop dprokop left a comment

Choose a reason for hiding this comment

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

LGTM, but please let's get rid of feature toggles reference in scenes.

@leeoniya leeoniya merged commit d9417ac into main Apr 2, 2026
14 checks passed
@leeoniya leeoniya deleted the leeoniya/clearPreviousData branch April 2, 2026 14:42
@scenes-repo-bot-access-token
Copy link
Copy Markdown

🚀 PR was released in v7.3.6 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Increment the patch version when merged release Create a release when this pr is merged released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants