borgar / textbox

Library to layout text for display on SVG or Canvas.
Other
26 stars 6 forks source link

Use OffscreenCanvas when available #26

Closed mattgrid closed 2 years ago

mattgrid commented 2 years ago

A Google Chrome Developers session from 2019 states that OffscreenCanvas has better performance than <canvas> even when it's running on the main thread. Their benchmarks showed that:

The second benchmark is of the most value to this library. It's a bit of a micro-optimisation, but it will have benefits if a lot of text measurement is going on.

OffscreenCanvas is available in Chrome and Edge (since 2018 and 2020 respectively). Other browsers will continue to use <canvas> to measure text.

mattgrid commented 2 years ago

Sorry, just realised I created this with the wrong GitHub account (there's an ugly mismatch between the committer and the creator of the PR). I'll recreate this with the correct account.