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

Chart updates to improve stability, possible fix for infinite loop #18329

Merged
merged 2 commits into from
Oct 24, 2023

Conversation

karwosts
Copy link
Contributor

@karwosts karwosts commented Oct 22, 2023

Proposed change

Two updates to history charts to attempt to improve rendering stability:

First is an update to not recompute start/end time in the render function of state-history-charts, as render is called after a child chart fires a y axis width change. That event should trigger a re-render of the children with different axis padding value, but it should not functionally change the data in the chart. I think this continual re-updating of time ranges and therefore data on each re-render can sometimes contribute to infinite render loops.

Second change is an escape hatch in the chart base that tries to detect if it caught in an infinite loop of rerendering layout padding changes (as has happened a few times in the past, when chart.js gets into an oscillation where it keeps flipping back and forth between two different axis width values on each render), and if it does, shows a warning and stops trying to maintain axis alignment to break the infinite loop, I think this could potentially prevent a hard browser hang. These cases are often difficult to predict and difficult to reproduce, sometimes depending on the time of day due to how chart.js lays out the tick labels. After making the first change above I am not currently able to trigger this case in my dev instance, but it may be helpful to speculatively prevent future issues, versus letting browser hang occur and trying to debug afterward.

I have a pathological test view with dozens of charts of varying options in various grid sizes, and without these changes I am occasionally (but not always) able to trigger a hard lockup in the browser when aggressively resizing the window. After making these changes I am not able to trigger a hang, so they seem to be helping.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

if (this._paddingUpdateCount > 300) {
this._paddingUpdateLock = true;
// eslint-disable-next-line
console.warn(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
console.warn(
console.error(

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should just throw, and log in the core log so people can report it...

this._paddingYAxisInternal = this.paddingYAxis;
if (changedProps.size === 1 && changedProps.has("paddingYAxis")) {
this._paddingUpdateCount++;
if (this._paddingUpdateCount > 300) {
Copy link
Member

Choose a reason for hiding this comment

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

If this happens in 2 secs, it is pretty bad, we should fix that 😓

@bramkragten bramkragten enabled auto-merge (squash) October 24, 2023 20:06
@bramkragten bramkragten merged commit 3e6ab8b into home-assistant:dev Oct 24, 2023
8 checks passed
@karwosts karwosts deleted the chart-stability-updates branch February 17, 2024 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants