Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@rakudrama
Copy link
Contributor

@rakudrama rakudrama commented Aug 9, 2023

The PR improves the code size and runtime performance of fallback font selection.

Performance improvements

Initialization of the data structures to support fallback font selection has been moved from creating the FallbackFontManager (first frame) to the first use, i.e. the first frame actually needing a fallback font.

The numbers reported below are for a lightly edited version of the counter demo that appends to the counter about ~300 missing code points that need ~25 fallback fonts to cover the missing code points. Timings taken from a few profiles on my performance workstation.

Before After
FallbackFontManager() ~100ms <2ms
First need 0ms 12ms
Subsequent need 20-30ms <1ms

Size improvements

Before After Δ
main.dart.js 1586405 1477319 -109086 (-6.87%)
brotli -9 427304 401611 -25693 (-6.01%)

Algorithm notes

Startup

The old algorithm built an interval tree from the code point ranges of the ~140 fallback fonts and uses the interval tree to build a list of fonts that support each missing code point. The new algorithm uses a binary search map that directly produces the list of fonts. There are fewer binary search ranges (~22k) than the aggregate ranges for all the fonts (~26k).
Most of the startup time gain comes from using a data unpacks directly into a useful form rather than needing processing to build an interval tree (~12ms vs ~100ms).

Running

The runtime for font selection is greatly improved for several reasons

  • The code point space is partitioned into components so that code point counting can be batched.
  • When a font is selected, the counts are updated incrementally rather than being recomputed.
  • The counts are held in fields of the NotoFont and component objects rather than in Maps or Sets.

Batching, incremental update and avoiding hash tables are roughly multiplicative in effect.

Issues

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Aug 9, 2023
Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

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

LGTM with nits

Thanks so much for this contribution!

@rakudrama rakudrama marked this pull request as ready for review August 31, 2023 02:04
@rakudrama
Copy link
Contributor Author

@eyebrowsoffire PTAL

Copy link
Contributor

@eyebrowsoffire eyebrowsoffire left a comment

Choose a reason for hiding this comment

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

Thank you so much for taking the time to do all this! This is going to be an amazing improvement.

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 31, 2023
@auto-submit auto-submit bot merged commit b867c4d into flutter:main Aug 31, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 31, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants