question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Improvements to browser frame-rate during Dataflow evaluation

See original GitHub issue

Hey there, long-time library user, first-time issue raiser šŸ‘‹

Iā€™ve recently been looking at trying to improve the performance of dashboards that render multiple Vega charts with a large amount of data. I found a way to improve the FPS of Vega when rendering multiple charts from 0 to 5.5, and I thought Iā€™d post it here to discuss.

Problem

When multiple Vega charts are created at the same time - Vega never ā€˜takes a breakā€™ to let other browser events be triggered & handled. Once vega-embed is called, itā€™ll be in a tight evaluation block until itā€™s managed to render the chart completely. This can cause the webpage to ā€˜hangā€™ or feel ā€˜non-responsiveā€™ since the browser isnā€™t able to respond to any user input events.

Iā€™ve created an example code-sandbox https://vxdyv.csb.app/ (src) that demonstrates the issue:

  1. Click Render Charts
  2. Observe that the CSS animated spinner ceases to rotate, as vega is doing a lot of uninterrupted data processing and canvas rendering so thereā€™s no chance for a DOM render.

Potential Solution *

The change I found, that improves the FPS from 0 to 5-6 (with almost negligible impact on the rendering time), is by wrapping the Dataflow.prototype.evaluate with requestIdleCallback.

You can see this for yourself with the same demo I linked before, by toggling the ā€˜Apply Patchā€™ checkbox before clicking ā€˜Render Chartsā€™.

The code change I made is to https://github.com/vega/vega/blob/master/packages/vega-dataflow/src/dataflow/run.js#L28

export async function evaluate(encode, prerun, postrun) {
  await new Promise(resolve => requestIdleCallback(resolve));
  ...
}

* requestIdleCallback isnā€™t supported in Safari or IE, so itā€™s not a silver bullet yet

Other solutions?

In theory, Iā€™d have imagined that vega would do some sort of streaming or work chunking, so that it could schedule work intermittently without continually blocking the thread. Originally, I was ambitiously looking for the one place that vega called out to do the processing of the scenegraph - before it rendered it using canvas/svg, but I wasnā€™t familiar enough with vegaā€™s codebase and how everything fit together to track that down (my conclusion was that the view/dataflow graph are fairly closely coupled - and that processing the data separately, e.g. in worker threads, is a much larger piece of work.)

Would love to hear any suggestions or feedback you have on how we can improve the framerate when rendering charts with large amounts of data, I know youā€™re already looking at improving performance in https://github.com/vega/vega/issues/2619 and Iā€™m happy to contribute however I can. I think - in the absence of moving the work entirely off the main thread using worker threads or some other approach - that measuring not only how long charts take to render but also the average FPS for the render to be super important going forward.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
scottsidwellcommented, Jul 23, 2020

Hey sorry for the delay!

Unfortunately requestAnimationFrame or setTimeout donā€™t work they have significantly different semantics to requestIdleCallback.

Multiple calls to requestAnimationFrame() will schedule all work right before the next browser repaint Similarly, multiple calls to setTimeout() will schedule all work to run after (at least) X milliseconds

requestIdleCallback() will instead maintain a work queue that waits for the browser to be ā€œidleā€ before executing the next callback in its list. What this means is that compared to the other two functions, multiple vega charts scheduling callbacks will have their rendering throttled by how busy the browser is (instead of simply delaying their rendering by an interval and then all running at once).


If anything - the main intent behind this ticket was to draw some attention to the issue we were having when rendering multiple large charts at the same time. Iā€™d love to find a way for vega to more incrementally process data without impacting latency-critical events such as animation and input response on large inputs, but I recognise itā€™s a really hard problem and appreciate all the work you do šŸ™‚

0reactions
domoritzcommented, Jan 20, 2022

@jheer might be interested in your idea. Iā€™ll reopen and let him close.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding and optimizing dataflows refresh - Power BI
To better understand how a dataflow refresh operation performs, review the Refresh History for the dataflow by navigating to Dataflow > SettingsĀ ...
Read more >
Dataflow and processes required to extrude 3D features in the ...
Dataflow and processes required to extrude 3D features in the web browser ... the real-time frame rate of the scene was improved by...
Read more >
Specify recording frame rate - XProtect VMS products
On the Record tab, in the Recording frame rate: (JPEG) box, select or enter the recording frame rate (in FPS, frames per second)....
Read more >
Implication of Optimizing NPU Dataflows on Neural ...
The dataflow simulation framework outputs the optimal dataflow with a Look-Up Table (LUT) containing the latency in processing every candidate operator. Then,Ā ...
Read more >
Animation performance and frame rate - MDN Web Docs
The process a browser uses to paint changes to a page when an element is animating CSS properties can be described as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found