Skip to content

Support --tree-shake-icons for the web #57181

@jonahwilliams

Description

@jonahwilliams

Currently --tree-shake-icons is on by default for mobile & desktop and disabled for the web.

Background

--tree-shake-icons uses the const_finder binary to parse the tree-shaken kernel file produced by frontend_server/TFA before it is fed to gen_snapshot for release builds. This kernel file should contain const references to all IconData used within an application. By collecting the set of code points and font families, we can thin the set of bundled fonts.

Problem

Unlike mobile/desktop, web release builds do not use the frontend_server or gen_snapshot, instead the entire process is handled by dart2s, from source to JavaScript. While dart2js supports tree-shaking as well, it never surfaces the tree-shaken kernel from the build process so it can be parsed by const finder. Initially it seemed like we could run with --cfe-only on dart2js, but this produces an un-tree-shaken kernel file, meaning it likely contains many more icons than are actually used.

Solutions

A few possible solutions were discussed, and some we dismissed:

  1. Use a frontend_server generated kernel file with TFA applied.

It's not clear if this would actually work, since the VM and dart2js platforms have different entrypoints, which could lead to different code being retained. A more trivial case would be something like a conditional import which contained different icons in vm/javascript branches. It would also require two almost identical compilations.

  1. Add dart2js kernel target to frontend_server

This is a less hacky version of (1). If we use the right kernel target and platform, then in theory we remove some of the obvious cases where tree shaking is wrong. This still leaves the possibility that there are non-trivial edge cases where dart2js tree-shaking and TFA tree-shaking differ. I haven't yet proven to myself this is an issue

  1. Teach dart2js to TFA

This seems like it would be a rather intrusive change to the compilers, and not clear that it would actually be better. Any decision to use TFA in dart2js would need to be made by the Dart web compilers team.

  1. Teach dart2js to write tree-shaken kernel to file

According to discussion with the Dart web compilers team, this doesn't really exist in dart2js today .

Metadata

Metadata

Labels

P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilitydependency: dartDart team may need to help usengineflutter/engine related. See also e: labels.platform-webWeb applications specificallytoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions