Skip to content

Remove canvas style attribute update when changing font weight#8733

Merged
davepagurek merged 2 commits into
dev-2.0from
variable-font-perf
Apr 27, 2026
Merged

Remove canvas style attribute update when changing font weight#8733
davepagurek merged 2 commits into
dev-2.0from
variable-font-perf

Conversation

@davepagurek
Copy link
Copy Markdown
Contributor

Resolves #8732

Changes

Previously, in addition to changing ctx.font, we would set canvas.style['font-variation-settings'] to set the font weight. This used to be necessary to get all browsers to do variable font weight. However, this CSS update causes a relayout on the page each time you change it, which can be quite costly when doing it many times per frame.

That was set up in late 2024. Testing now, in 2026, it seems like neither Chrome nor Firefox has problems without this CSS update. We previously took it out for Safari, as it was actively messing up its rendering. It looks like now we can just take it out for everyone.

This now gets me 60fps on both Chrome and Safari.

Live: https://editor.p5js.org/davepagurek/sketches/JFCOpYLg9

PR Checklist

@p5-bot
Copy link
Copy Markdown

p5-bot Bot commented Apr 19, 2026

Continuous Release

CDN link

Published Packages

Commit hash: ce973e2

Previous deployments

549b44a


This is an automated message.

@davepagurek
Copy link
Copy Markdown
Contributor Author

@Qianqianye does work for you on your test sketch?

@davepagurek
Copy link
Copy Markdown
Contributor Author

I'm going to merge this one in for now since it's at least an improvement, but we can definitely open more PRs if we see more cases that we can improve upon further.

@davepagurek davepagurek merged commit bbfd9ab into dev-2.0 Apr 27, 2026
8 checks passed
@davepagurek davepagurek deleted the variable-font-perf branch April 27, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant