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

Improve Canvas Text Renderer Performance #319

Merged
merged 5 commits into from
Jul 5, 2024

Conversation

frank-weindel
Copy link
Collaborator

@frank-weindel frank-weindel commented Jul 2, 2024

  • Simplify/improve canvas renderer performance by utilizing child nodes and ImageTexture factory.
  • All canvas text is now laid out when created, but not actually rasterized until the text becomes renderable (inbounds, positive alpha, etc)
  • Canvas textures are now properly able to be cleaned up when they become unrenderable.

TODO

@frank-weindel
Copy link
Collaborator Author

@wouterlucas Could you help me performance test this if you have a chance?

@frank-weindel frank-weindel added the performance Performance enhancement label Jul 2, 2024
@philippe-wm
Copy link

When the text of a node changes, does that require creating a new texture or do you update the text of the texture?


createNode(props: Partial<CoreNodeWritableProps>) {
const resolvedProps = this.resolveNodeDefaults(props);
const node = new CoreNode(this, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a waste to clone the resolvedProps just to add shaderProps: null

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will fix.

state.textureNode.texture = texture;
} else {
// Create a new texture node
const textureNode = this.stage.createNode({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why creating a sub node? Is that to decouple the text node size and the texture?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah pretty much. I did do a pass trying to simply update the TextNode's texture but this was the path of least resistance to be able to do this without changing the size characteristics of canvas TextNodes (i.e. without breaking a ton of tests). Open to suggestions for improvement, however I think this in general will be more performant than what we have right now.

@frank-weindel
Copy link
Collaborator Author

When the text of a node changes, does that require creating a new texture or do you update the text of the texture?

In this case I'm creating a new texture. Generally Texture instances have been treated as immutable objects. This doesn't necessarily have to be the case. But it's not an area I have time atm to think about.

@wouterlucas
Copy link
Contributor

wouterlucas commented Jul 2, 2024

@wouterlucas Could you help me performance test this if you have a chance?

See here:
image

All 3 renderer using Canvas fonts. If you want I can add the same codebase that the PR is from and enable MSDF fonts for comparison. Though it will be fastest.

But still a bit away from L2's performance.

@frank-weindel frank-weindel force-pushed the fix/canvas2d-fonts-performance branch from 94a56e8 to 63ff8ba Compare July 4, 2024 01:10
@frank-weindel frank-weindel marked this pull request as ready for review July 4, 2024 01:17
@frank-weindel frank-weindel force-pushed the fix/canvas2d-fonts-performance branch from 63ff8ba to f443716 Compare July 5, 2024 14:17
wouterlucas and others added 3 commits July 5, 2024 10:26
- Canvas Text Textures are now managed properly by the texture manager
- Also add willReadFrequently option to text drawing canvas element context
@frank-weindel frank-weindel force-pushed the fix/canvas2d-fonts-performance branch from f443716 to 3ac9adf Compare July 5, 2024 14:26
Minor changes to text rendering due to eliminating multi-page implementation
@frank-weindel frank-weindel changed the title Fix/canvas2d fonts performance Improve Canvas Text Renderer Performance Jul 5, 2024
@frank-weindel frank-weindel merged commit be06ab7 into dev Jul 5, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants