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

Render reported before complete #2124

Closed
drewdaemon opened this issue Aug 2, 2023 · 6 comments · Fixed by #2131
Closed

Render reported before complete #2124

drewdaemon opened this issue Aug 2, 2023 · 6 comments · Fixed by #2131
Labels
:all Applies to all chart types API Changes the external API types enhancement New feature or request

Comments

@drewdaemon
Copy link
Contributor

drewdaemon commented Aug 2, 2023

Describe the issue
The library is reporting a complete render one tick too early.

To Reproduce
Add a breakpoint or log statement to the body of the onRenderChange callback for a chart.

Expected behaviour
onRenderChange should only be called with true when the chart has been rendered to the canvas. Instead, it is being called a tick before the chart is drawn.

Screenshots

Screen.Recording.2023-08-02.at.10.14.03.AM.mov

Look for "visualization took to render after data received" in the above recording ^^. It is logged before the chart is visible.

Version (please complete the following information):

  • OS: OSX
  • Browser: Brave, Safari
  • Elastic Charts: 59.1.0

Additional context
This behavior throws off our performance measurements, making it look like we're rendering the chart faster than we actually are.

The problem may originate with this change.

Errors in browser console
None

@nickofthyme
Copy link
Collaborator

Related to changes in #1730

@markov00
Copy link
Member

markov00 commented Aug 3, 2023

As commented here #1730 (comment)
the original callbacks where wrapped around a RAF because:

If the user attaches very long sync function to a callback then the rendering phase of the event loop will start only after that sync function has completed, freezing the chart until the end of the callback.
Adding a RAF will push the callback in the queue and runs it after the rendering phase, reducing the freeze effect.

We changed that mechanism to give the consumer the control over how to handle that call, but we can probably go back, at least for the onRenderChange

@markov00
Copy link
Member

markov00 commented Aug 3, 2023

@drewdaemon in the meantime can you check this works on lens side, by creating something like that:

const onRenderChangeFn = (rendered: boolean) => {
    window.requestAnimationFrame(() => changeSomethingOnRenderingFunction(rendered));
};

<Settings onRenderChange={onRenderChangeFn}

@drewdaemon
Copy link
Contributor Author

in the meantime can you check this works on lens side

Thanks @markov00 . This does resolve the issue.

we can probably go back, at least for the onRenderChange

I'm in favor of this. It would be nice to have a fix here in the charts library, since we otherwise have to remember to add this to every expression renderer.

@markov00
Copy link
Member

markov00 commented Aug 3, 2023

@nickofthyme what do you think about bringing back the RAF only for the onRenderChange?

@markov00 markov00 added enhancement New feature or request API Changes the external API types :all Applies to all chart types and removed bug Something isn't working labels Aug 3, 2023
@nickofthyme
Copy link
Collaborator

Yeah I think that's the best solution, I don't see another way to fix it.

mistic pushed a commit to elastic/kibana that referenced this issue Aug 7, 2023
## Summary
This PR instruments the code to track a few key editor performance
metrics. This is to prepare for adding a Lens editor performance
journey.

Metrics
- initial load of main chart
  - time to load data
  - time to render
- time to initially load and render all suggestions

For this PR, each metric is reported to the console (commented out to
pass the linter). When the journey is added, the console statements will
be converted to analytics service calls so that they show up as metrics
in the journey dashboard.

I made a few changes to increase the accuracy of the metrics.
- wrapping render-complete callbacks in `requestAnimationFrame` calls as
a temporary solution to
elastic/elastic-charts#2124
- fixing a multiple-subscription issue in the workspace panel

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
crespocarlos pushed a commit to crespocarlos/kibana that referenced this issue Aug 8, 2023
## Summary
This PR instruments the code to track a few key editor performance
metrics. This is to prepare for adding a Lens editor performance
journey.

Metrics
- initial load of main chart
  - time to load data
  - time to render
- time to initially load and render all suggestions

For this PR, each metric is reported to the console (commented out to
pass the linter). When the journey is added, the console statements will
be converted to analytics service calls so that they show up as metrics
in the journey dashboard.

I made a few changes to increase the accuracy of the metrics.
- wrapping render-complete callbacks in `requestAnimationFrame` calls as
a temporary solution to
elastic/elastic-charts#2124
- fixing a multiple-subscription issue in the workspace panel

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
bryce-b pushed a commit to bryce-b/kibana that referenced this issue Aug 9, 2023
## Summary
This PR instruments the code to track a few key editor performance
metrics. This is to prepare for adding a Lens editor performance
journey.

Metrics
- initial load of main chart
  - time to load data
  - time to render
- time to initially load and render all suggestions

For this PR, each metric is reported to the console (commented out to
pass the linter). When the journey is added, the console statements will
be converted to analytics service calls so that they show up as metrics
in the journey dashboard.

I made a few changes to increase the accuracy of the metrics.
- wrapping render-complete callbacks in `requestAnimationFrame` calls as
a temporary solution to
elastic/elastic-charts#2124
- fixing a multiple-subscription issue in the workspace panel

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:all Applies to all chart types API Changes the external API types enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants