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

BitmapText optimisation #6641

Merged
merged 8 commits into from
May 28, 2020
Merged

BitmapText optimisation #6641

merged 8 commits into from
May 28, 2020

Conversation

GoodBoyDigital
Copy link
Member

Description of change

As BitmapFont has now become much more accessible to our users thanks to recent efforts from the team, figured we could do with doing a bit of an optimisation pass for how bitmap fonts are rendering!

Main thing is that instead of rendering each letter as a sprite, we now render them as a mesh. This has a few benefits straight out of the box!

  • lower memory footprint as we don't needs loads of sprites anymore, just a mesh or two
  • faster creation updateText
    • pooling objects in this function.
    • including the meshes.
    • mesh buffers only reallocated if size grows.
  • faster runtime render
    • as the text is either batched automatically if small.
    • OR if its massive it is rendered in a single draw call (super fast, as no per character update is required)
    • tinting no longer required an updateText call as we leverage the mesh tint functionality.
  • Ensure support for multipage fonts still works (made things a bit trickier :P)
  • Added a couple of interfaces to some internal BitmapText bits.
  • No surface API changes, all under the hood stuff.
  • Character limit is about 11,000 - which is a lot of text :)
Pre-Merge Checklist
  • Documentation is changed or added
  • Lint process passed (npm run lint)
  • Tests passed (npm run test)

@GoodBoyDigital GoodBoyDigital added the 👀 Needs Review PR needs to be reviewed by someone on the core team. label May 24, 2020
@ShukantPal
Copy link
Member

@GoodBoyDigital I see Matt's commits in this PR, maybe you need to rebase it?

Copy link
Member

@ShukantPal ShukantPal left a comment

Choose a reason for hiding this comment

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

This sounds nice - I have a few suggestions related to readability & see a potential problem with how the data flows around.

packages/text-bitmap/src/BitmapText.ts Show resolved Hide resolved
packages/text-bitmap/src/BitmapText.ts Outdated Show resolved Hide resolved
packages/text-bitmap/src/BitmapText.ts Outdated Show resolved Hide resolved
packages/text-bitmap/src/BitmapText.ts Outdated Show resolved Hide resolved
packages/text-bitmap/src/BitmapText.ts Outdated Show resolved Hide resolved
- optimise bitmapfont renderer
- use mesh instead of sprites
   - optimised tinting
   - smart batching
   - less memory overhead
- support for multipage fonts
- pooling data objects
- expose `baseTexture` uid as readonly
@bigtimebuddy
Copy link
Member

This is awesome @GoodBoyDigital! Super excited about our new and improved BitmapText.

Some tests might need to be looked at, these are failing:

  1. PIXI.BitmapText
    should render text even if there are unsupported characters:
  2. PIXI.BitmapText
    should support font without page reference:

@themoonrat
Copy link
Member

Question: How does this effect the Canvas renderer?

GoodBoyDigital and others added 2 commits May 24, 2020 15:29
Co-authored-by: Matt Karl <matt@mattkarl.com>
@GoodBoyDigital
Copy link
Member Author

Hey @SukantPal , thanks for the feedback man! Push some changes. Let me know if its all cool 👍

@GoodBoyDigital
Copy link
Member Author

@bigtimebuddy , will look at those tests now..

@GoodBoyDigital
Copy link
Member Author

Question: How does this effect the Canvas renderer?

Good question. i will test, it should work but I guess would technically be slower perf than the old method. If it turns out to be a deal breaker and we should keep the previous method around and move it into Canvas Renderer.

@codecov-commenter
Copy link

codecov-commenter commented May 24, 2020

Codecov Report

Merging #6641 into dev will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev    #6641   +/-   ##
=======================================
  Coverage   82.59%   82.59%           
=======================================
  Files          35       35           
  Lines        1724     1724           
=======================================
  Hits         1424     1424           
  Misses        300      300           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 311d7e1...7221292. Read the comment docs.

charRenderData.position.x = pos.x + charData.xOffset + (this._letterSpacing / 2);
charRenderData.position.y = pos.y + charData.yOffset;

chars.push(charRenderData);
Copy link
Member

Choose a reason for hiding this comment

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

What do ya think about optimizing this one as well?

Instead of pushing each character to the (initially) zero-length array, do something like:

// textLength is a _good_ heuristic of the actual no. of chars
const chars: CharRenderData = new Array(textLength);
let charsRendered = 0;

for (let i = 0; i < textLength; i++) {
     if (<skipCondition>) {
         continue;
     }  

     chars[charsRendered] = charREnderData;
     ++charsRenderered;
}

// Make sure undefined slots aren't at the end of the array, if needed
chars.length = charsRendered;

Copy link
Member

Choose a reason for hiding this comment

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

@GoodBoyDigital I'm leaving this one on your will. It would be cool to do this optimization but not necessarily required.

Copy link
Member

Choose a reason for hiding this comment

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

^^^

packages/text-bitmap/test/BitmapText.js Show resolved Hide resolved
@bigtimebuddy
Copy link
Member

Seems to still render fine on canvas:
https://pixijs.download/feature/turbo-bitmap-fonts/pixi-legacy.min.js
https://jsfiddle.net/bigtimebuddy/hzrx6p47/

Copy link
Member

@bigtimebuddy bigtimebuddy left a comment

Choose a reason for hiding this comment

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

Overall, I'm happy with this @GoodBoyDigital. I think it represents a big step forward and with BitmapFont will be a huge win for 5.3.0. I'm sure you and @SukantPal can sort out any stylistic issues, otherwise g2g!

- fixed batching issue
- added unit test for adding / removing children
- fixed issue found when making unit test :)
- don't call updateText on creation
@GoodBoyDigital
Copy link
Member Author

Ok, good to go now! Final updates and new unit test

  • fixed batching issue
  • added unit test for adding / removing children
  • fixed issue found when making unit test :)
  • don't call updateText on creation

charRenderData.position.x = pos.x + charData.xOffset + (this._letterSpacing / 2);
charRenderData.position.y = pos.y + charData.yOffset;

chars.push(charRenderData);
Copy link
Member

Choose a reason for hiding this comment

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

^^^

@bigtimebuddy bigtimebuddy added ✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t and removed 👀 Needs Review PR needs to be reviewed by someone on the core team. labels May 26, 2020
@bigtimebuddy bigtimebuddy merged commit cfc05d1 into dev May 28, 2020
@bigtimebuddy bigtimebuddy deleted the feature/turbo-bitmap-fonts branch May 28, 2020 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✅ Ready To Merge Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants