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

[web] Split all 1MB+ fallback fonts (including CJK) #56388

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Nov 5, 2024

By splitting all large fallback fonts (1MB+) into smaller parts, we get faster downloads and fast decoding.

Some fonts are split into 100+ parts, and that's causing main.dart.js's size to grow by ~47KB (Brotli-compressed). The increase in size is due to the extra data we have to store about all the parts of these fonts.

The PR also makes changes to ensure we don't download the same license file 100 times (once for each part of the split font).

Fixes flutter/flutter#138288
Part of flutter/flutter#153974

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Nov 5, 2024
@mdebbar mdebbar marked this pull request as draft November 5, 2024 21:34
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

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!

if (failedUrl != null) {
throw ToolExit('Could not find license attribution at: $failedUrl');
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unnecessary empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return urlString.substring(expectedUrlPrefix.length);
}

Future<String?> _checkForLicenseAttributions(
Copy link
Contributor

Choose a reason for hiding this comment

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

document that this method returns a non-null String with the non-conforming license URL if the license fails the check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@mdebbar mdebbar marked this pull request as ready for review November 5, 2024 21:46
@mdebbar
Copy link
Contributor Author

mdebbar commented Nov 5, 2024

I still need to do something about these.

@harryterkelsen
Copy link
Contributor

I still need to do something about these.

I think instead of comparing the font to the (single) Noto Sans SC, TC, etc you can basically replace the checks for "if font == _notoSansSC" with "if font.name == 'Noto Sans SC'"

@mdebbar
Copy link
Contributor Author

mdebbar commented Nov 5, 2024

I still need to do something about these.

I think instead of comparing the font to the (single) Noto Sans SC, TC, etc you can basically replace the checks for "if font == _notoSansSC" with "if font.name == 'Noto Sans SC'"

Yep, that and there are also some list.contains(_notoSansSC) that need to change.

Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

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

Just a small suggestion to improve error reporting a little bit.

Comment on lines +520 to +522
'Noto Sans Cuneiform',
'Noto Sans Duployan',
'Noto Sans Egyptian Hieroglyphs',
Copy link
Member

Choose a reason for hiding this comment

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

If we don't want to bloat the main file in the general case... Have we thought of trimming the list of fallback fonts to "scripts currently in use today", with an opt-in to the full set? (Maybe vending 2 different versions of the font metadata file?)

@@ -65,6 +65,13 @@ class RollFallbackFontsCommand extends Command<bool>
...await _processSplitFallbackFonts(client, splitFallbackFonts),
...await _processFallbackFonts(client, apiFallbackFonts),
];

final String? failedUrl = await _checkForLicenseAttributions(client, fallbackFontInfo);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe return a List<String> or Set<String> with all the fonts that might have failed, and then do if (failedUrls.isNotEmpty) to throw? That way we can report all the fonts that have a problem at once.

Comment on lines +531 to +535
final String urlString = fontUri.toString();
if (!urlString.startsWith(expectedUrlPrefix)) {
throw ToolExit('Unexpected url format received from Google Fonts API: $urlString.');
}
return urlString.substring(expectedUrlPrefix.length);
Copy link
Member

@ditman ditman Nov 5, 2024

Choose a reason for hiding this comment

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

This should could be a regex :P (now we have two problems!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flutter web's TextField displays gibberish for Unicode inputs, such as Korean characters (CJK)
3 participants