From bf6bee76c215f3fc8d14c15a88b520bd788d8f97 Mon Sep 17 00:00:00 2001 From: Jo Liss Date: Sat, 29 Jun 2024 16:01:50 +0100 Subject: [PATCH] Update OffscreenCanvas documentation, as it is widely available now --- docs/general/performance.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/general/performance.md b/docs/general/performance.md index bc6cedb7205..9262630e9c0 100644 --- a/docs/general/performance.md +++ b/docs/general/performance.md @@ -72,16 +72,16 @@ new Chart(ctx, { }); ``` -## Parallel rendering with web workers (Chromium only) +## Parallel rendering with web workers -Chromium (Chrome: version 69, Edge: 79, Opera: 56) added the ability to [transfer rendering control of a canvas](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/transferControlToOffscreen) to a web worker. Web workers can use the [OffscreenCanvas API](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas) to render from a web worker onto canvases in the DOM. Chart.js is a canvas-based library and supports rendering in a web worker - just pass an OffscreenCanvas into the Chart constructor instead of a Canvas element. Note that as of today, this API is only supported in Chromium based browsers. +As of 2023, modern browser have the ability to [transfer rendering control of a canvas](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/transferControlToOffscreen) to a web worker. Web workers can use the [OffscreenCanvas API](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas) to render from a web worker onto canvases in the DOM. Chart.js is a canvas-based library and supports rendering in a web worker - just pass an OffscreenCanvas into the Chart constructor instead of a Canvas element. By moving all Chart.js calculations onto a separate thread, the main thread can be freed up for other uses. Some tips and tricks when using Chart.js in a web worker: * Transferring data between threads can be expensive, so ensure that your config and data objects are as small as possible. Try generating them on the worker side if you can (workers can make HTTP requests!) or passing them to your worker as ArrayBuffers, which can be transferred quickly from one thread to another. * You can't transfer functions between threads, so if your config object includes functions you'll have to strip them out before transferring and then add them back later. * You can't access the DOM from worker threads, so Chart.js plugins that use the DOM (including any mouse interactions) will likely not work. -* Ensure that you have a fallback if you support browsers other than the most modern Chromium browsers. +* Ensure that you have a fallback if you support older browsers. * Resizing the chart must be done manually. See an example in the worker code below. Example main thread code: