Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: Limit data layer state updates #724

Merged
merged 6 commits into from
May 15, 2024

Conversation

torkelo
Copy link
Member

@torkelo torkelo commented May 8, 2024

Various performance fixes

  •  We were using infinity replay subjects so when coming back to a scene data layers emitted all their previous emitted results
  • Ignore replayed data layer results that has already been processed (this happens when a data provider get's re-activated, we subscribe the the SceneDataLayerSet this causes the ReplaySubject to emit last data, even if that has already been incorporating into the current state). Created a new DataLayersMerger that can detect when a result has already been seen.
  • In SceneQueryRunner ignore updating state when data layers are received if there are no annotations (And the previous result also had no annotations)
📦 Published PR as canary version: 4.22.0--canary.724.9079775010.0

✨ Test out this PR locally via:

npm install @grafana/scenes@4.22.0--canary.724.9079775010.0
# or 
yarn add @grafana/scenes@4.22.0--canary.724.9079775010.0

@torkelo torkelo added release Create a release when this pr is merged minor Increment the minor version when merged labels May 8, 2024
const baseStateUpdate = this.state.data ? this.state.data : { ...emptyPanelData, timeRange: timeRange.state.value };
// Skip unnessary state updates
if (
alertState === this.state.data?.alertState &&
Copy link
Member

Choose a reason for hiding this comment

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

This condition is quite hard to reason about, as it assumes that one knows that the alert state is a reference to an state taken from the alert states results. I wonder if it wouldn't be easier if we didn't set that particular alert state reference in the state but always create a new object, and here instead rely on object equality rather than reference equalit? WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

@dprokop pushed update that switched to isEqual instead, for some reason I thought alertState was an enum :)

Copy link
Member

@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.

Gave it another look (thanks for updating the alerts state quality check!) and it looks good. I've also tested some test dashboards with annotations and it works great.

@torkelo torkelo merged commit 1b5b3bd into main May 15, 2024
3 checks passed
@torkelo torkelo deleted the data-state-updates-performance-updates branch May 15, 2024 09:36
@grafanabot
Copy link
Contributor

🚀 PR was released in v4.22.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged release Create a release when this pr is merged released
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants