Skip to content

[engine] Defer default font manager resolution to first use for platforms that have a prefetching API only - #196377

Merged
auto-submit[bot] merged 2 commits into
flutter:masterfrom
xRossKoh:defer-prefetched-default-font-manager
Nov 19, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:masterfrom
xRossKoh:defer-prefetched-default-font-manager

Conversation

@xRossKoh

Copy link
Copy Markdown
Contributor

This is an attempt to re-implement flutter-team-archive/engine#28978, which was previously closed due to concerns over potential latency regressions during frame workload on platforms that do not have a prefetching API. This change gates the above change to platforms that have a prefetching API only. It uses the existing settings_.prefetched_default_font_manager parameter available at the engine layer to determine if the deferral should occur.

The Perfetto traces below validate the fix.

  • Hello Flutter app: image

  • On my app: image

#196376 is fixed by this PR.

Pre-launch Checklist

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

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions Bot added the engine flutter/engine related. See also e: labels. label Nov 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces deferred initialization of the default font manager in the Flutter engine, allowing it to be resolved on first use rather than blocking the UI thread during engine launch. Feedback suggests adding thread-safety annotations (FML_GUARDED_BY) to the member variables protected by default_font_manager_mutex_ in FontCollection to align with the Google C++ Style Guide and enable static verification of lock acquisition.

@jiahaog jiahaog added the CICD Run CI/CD label Nov 11, 2026
@gaaclarke
gaaclarke self-requested a review November 16, 2026 17:02
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 17, 2026
@gaaclarke gaaclarke added the CICD Run CI/CD label Nov 17, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks @xRossKoh, I have a few suggestions =)

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 17, 2026
@xRossKoh
xRossKoh requested a review from gaaclarke November 17, 2026 12:42
@gaaclarke gaaclarke added the CICD Run CI/CD label Nov 17, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks for the prompt response, I think these were good changes. I was a bit worried about potentially creating a temporal bug when offloading that work to the ui thread, but I think we are safe.

@xRossKoh
xRossKoh force-pushed the defer-prefetched-default-font-manager branch from 596d4c3 to ae50cfb Compare November 18, 2026 01:50
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 18, 2026
@jiahaog jiahaog added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Nov 18, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit

auto-submit Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196377, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 1 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a member of flutter-hackers before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@jiahaog jiahaog added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit

auto-submit Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196377, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label.

Kenneth Koh added 2 commits November 18, 2026 13:43
… embedder

On Android, `SkFontMgr_Android` eagerly parses `fonts.xml` and opens system font files during startup. Although `FlutterLoader` prefetches `txt::GetDefaultFontManager()` on a background thread and passes `--prefetched-default-font-manager` to defer `Engine::SetupDefaultFontManager()` until root isolate creation, `FontCollection::SetupDefaultFontManager()` still resolves `txt::GetDefaultFontManager()` eagerly before Dart `main()` runs, blocking the UI thread whenever the background scan is still in flight.

Add `DeferDefaultFontManager()` across `Engine` and `FontCollection` and invoke it from `Engine::Run()` when `settings_.prefetched_default_font_manager` is set, resolving `txt::GetDefaultFontManager()` lazily upon first font access in `txt::FontCollection` while preserving eager initialization when `prefetched_default_font_manager` is unset or `ReloadSystemFonts()` is called.
- Dispatch `Shell::ReloadSystemFonts` and `Shell::OnServiceProtocolReloadAssetFonts` font collection updates onto the UI task runner so the UI thread exclusively owns `FontCollection`, removing `default_font_manager_mutex_`.
- Make `GetFontManagersCount`, `GetFontManagerOrder`, and `GetDefaultFontManager` non-`const` instead of marking `default_font_manager_init_data_` and `default_font_manager_` `mutable`.
- Add and expand docstrings on `FontCollection::DeferDefaultFontManager` and `Engine::DeferDefaultFontManager` clarifying their relationship to `SetupDefaultFontManager`.
- Use `EXPECT_*` instead of `ASSERT_*` for value checks in `FontCollectionTests`.
- Add unit tests in `EngineTest` and `ShellTest` covering `Engine::Run` deferral behavior and cross-thread `Shell::ReloadSystemFonts`.
@xRossKoh
xRossKoh force-pushed the defer-prefetched-default-font-manager branch from ae50cfb to d101f51 Compare November 18, 2026 05:43
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 18, 2026
@jiahaog jiahaog added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Nov 18, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit

auto-submit Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/196377, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label.

@jiahaog jiahaog added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2026
@auto-submit

auto-submit Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/196377, Failed to enqueue flutter/flutter/196377 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Nov 19, 2026
Merged via the queue into flutter:master with commit 7d220bf Nov 19, 2026
26 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 19, 2026
flutter/flutter@06f32f8...e8cc6f3

2026-11-19 [email protected] Roll Skia from 280e0965687d to 3dfb69d709c7 (1 revision) (flutter/flutter#196970)
2026-11-19 [email protected] Update outdated `_formattedValues` documentation (flutter/flutter#195765)
2026-11-19 [email protected] [Impeller] Fix Vulkan GPU frame time metrics in benchmarks (flutter/flutter#196339)
2026-11-19 [email protected] Windows: Enable D3D11 multithread protection on ANGLE's device (flutter/flutter#196897)
2026-11-19 [email protected] Roll Skia from 7356c7627e87 to 280e0965687d (1 revision) (flutter/flutter#196957)
2026-11-19 [email protected] Roll Dart SDK from 091f346ad95c to d8d40cf9c21b (2 revisions) (flutter/flutter#196949)
2026-11-19 [email protected] Roll Skia from 73b9219fd1fa to 7356c7627e87 (4 revisions) (flutter/flutter#196951)
2026-11-19 [email protected] Roll Skia from 7bca23228537 to 73b9219fd1fa (1 revision) (flutter/flutter#196948)
2026-11-19 [email protected] [libimpeller] Fix swapped x and y glyph coordinates (flutter/flutter#196552)
2026-11-19 [email protected] [ios][spm]When using cocoapods plugin, give instruction that plugins may just need update (flutter/flutter#195853)
2026-11-19 [email protected] [web] Let the browser handle Control+wheel zoom outside of macOS (flutter/flutter#193362)
2026-11-19 [email protected] Fix focus violation when canRequestFocus set to false for all siblings in same build (flutter/flutter#191536)
2026-11-19 [email protected] Roll Skia from 9fc4f9e23d56 to 7bca23228537 (10 revisions) (flutter/flutter#196941)
2026-11-19 [email protected] Roll Dart SDK from 753488ede427 to 091f346ad95c (2 revisions) (flutter/flutter#196940)
2026-11-19 [email protected] iOS: Convert platform views to points with the frame's pixel ratio (flutter/flutter#196858)
2026-11-19 [email protected] [engine] Defer default font manager resolution to first use for platforms that have a prefetching API only (flutter/flutter#196377)
2026-11-18 [email protected] [flutter_tools] Add example app to package template and decouple platform configurations (flutter/flutter#192441)
2026-11-18 [email protected] [flutter_tools] Rebuild asset bundle when generated manifest content changes (flutter/flutter#191638)
2026-11-18 [email protected] Roll Skia from b11d69796f71 to 9fc4f9e23d56 (2 revisions) (flutter/flutter#196909)
2026-11-18 [email protected] [flutter_tools] Bump cupertino_icons to ^2.0.0 in app and module templates (flutter/flutter#196828)
2026-11-18 [email protected] Update iOS plugin language instructions (flutter/flutter#196614)
2026-11-18 [email protected] iOS: Add tests for rounded rect clips with per-corner/elliptical radii (flutter/flutter#196854)
2026-11-18 [email protected] Revert: [flutter_tools] Migrate lib/runner.dart off runInContext and overrides (flutter/flutter#196926)
2026-11-18 [email protected] Revert: Move macOS desktop builds to ThinLTO (flutter/flutter#196917)
2026-11-18 [email protected] [FGP] Offset split-APK versionCodes from a manifest-only versionCode (flutter/flutter#196561)
2026-11-18 [email protected] [flutter_tools] Migrate lib/runner.dart off runInContext and overrides (flutter/flutter#196387)
2026-11-18 [email protected] docs: remove broken image references from dev/snippets/README.md (flutter/flutter#195587)
2026-11-18 [email protected] Remove the FGP AGP-public-API migration coordination docs (flutter/flutter#196733)
2026-11-18 [email protected] [web] Skip stale safeBlur focus transfer when the element was refocused (flutter/flutter#196550)
2026-11-18 [email protected] Roll Skia from 81ee7327e81c to b11d69796f71 (4 revisions) (flutter/flutter#196900)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants