-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
This issue tracks development that will speed up asset manifest loading and parsing, which will in turn speed up the first asset load that a Flutter app performs.
This was originally intended to perform as one change (#113637), with followup clean-up/tech-debt then to follow (#114913). However, due to problems with specific g3 tests, this is being split up into smaller changes.
Background
When loading an asset for the first time, the framework has to load a file called the asset manifest, which contains information about assets available to the app (for example, where to find higher-resolution variants of images). This file is in the JSON format.
Reading the file from storage, decoding into UTF, and parsing it as JSON is generally slower than we'd like, especially since this is will all likely happen on first paint (since many apps include assets on their first screens).
The asset manifest (AssetManifest.json) is created at build time.
Desired Change
The idea is to use a binary format rather than JSON for the asset manifest file. In particular, we'll use the standard_message_codec package for encoding the manifest at build time and decoding it at runtime. This new manifest will be stored in a new file, AssetManifest.bin. In addition, for decoding the binary message, we'll lazily put off typecasting until we read individual keys--avoiding upfront typecasting for all entries. This will achieve a significant speedup for first asset load, especially on less powerful devices.
Tasks
[x] Update flutter_tools to produce AssetManifest.bin. #117233
[x] After that change rolls, update g3 tool code to produce AssetManifest.bin.
[x] Add new framework API for consuming the asset manifest. #118410 #119277
[x] Update framework to consume AssetManifest.bin #118782 #121322 #122505
[ ] After a full deprecation cycle and process, remove tool code that generates AssetManifest.json1
Footnotes
-
While AssetManifest.json is not officially documented, some users decided to depend on it based on recommendation from flutter developers. Removing it outright would break them. For example, Google Fonts reads it to determine whether or not a font can be loaded from the device rather than loading it over HTTP. ↩