Repository navigation
[flutter_tools] default tree-shake-icons to enabled and improve performance - #54923
Conversation
|
(once tests pass) |
|
So the deploy gallery shard has failed twice in a row with OOM. I'm going to mark this a WIP, I need to investigate whether we're using drastically more memory with this on by default. |
|
Running this locally I'm able to repro a large spike in memory pressure and my computer also locked up for a few seconds while running this (it doesn't for normal builds). |
|
Which command? Const_finder? |
|
just by running |
|
I also experience this when using this flag. For a few seconds, my machine becomes unresponsive with 100% CPU usage and a spike in used memory. Both for APK and appbundle (didn't test iOS or web). |
…ms/flutter into flip_tree_shake_icon_default
| // Only tree shake MaterialIcons-Regular.ttf font. | ||
| final bool isMaterialIcons = globals.fs.path | ||
| .basename(content.file.path) == kMaterialIconsFontName; | ||
| if (!isMaterialIcons || !await iconTreeShaker.subsetFont( |
There was a problem hiding this comment.
But... Why? What about Cupertino icons or font awesome icins?
There was a problem hiding this comment.
The intention of this routine was to only do work if the font file was used by an IconData instance. Is that not happening?
There was a problem hiding this comment.
As written this was spinning up a const finder instance for every single asset. Does this actually work with arbitrary icon sets? If so we could use something like the mime package to limit it to font files (ttf only?)
There was a problem hiding this comment.
The other change this would need is to limit the number of instances to 2 or 3, because each one seems to be quite heavy
There was a problem hiding this comment.
Ahh ok. Yes, this should work with any font that you refernece a glyph in using IconData .. or at least any TTF.
Limiting this to 2 or 3 instances should be fine. And it wasn't meant to run on non-ttf assets.
There was a problem hiding this comment.
The expectation is that this code
Why is the const finder running more than once? :\
There was a problem hiding this comment.
I figured it out, getIconData is fairly expensive, and we might be copying multiple assets at the same time. each one that hits this line before the first instance has finished will spawn a new const finder
There was a problem hiding this comment.
Ahh, yes. Ok. We should just trigger that to happen before the loop. I'm still a little confused about how multiple places are reaching this code before the first one finishes -are we missing an await somewhere?
There was a problem hiding this comment.
Because the out loop is a Future.wait, not a for loop
| if (input.lengthSync() < 12) { | ||
| return false; | ||
| } | ||
| final String mimeType = mime.lookupMimeType( |
There was a problem hiding this comment.
How confident are you that this won't cause new problems?
There was a problem hiding this comment.
I'm not confident about anything
There was a problem hiding this comment.
Maybe we can just move the mime chekc to a separate pr
There was a problem hiding this comment.
We might as well resolve this now if you have concerns :)
Are there non-ttf fonts that the icon_tree_shaker works with? Or does the hb subset utility have a list of supported formats?
There was a problem hiding this comment.
I guess this should be fairly safe. Mime sniffing can get funny, and we could get broken if the mime package changes the spelling of a type
There was a problem hiding this comment.
I'll add some more tests around this logic
There was a problem hiding this comment.
More tests added. If the spelling changes there was an existing test that fails, but I also added cases to verify we don't subset invalid fonts or non-ttf mime types
|
I enabled this for web too, but it doesn't actually work since --cfe-only does not do any const evaluation. Instead we'll need to add a dart2js target to the frontend server and produce kernel that way. |
|
One test failure, with a really nice error message too :D |
Description
Enable tree-shake-icons by default in profile/release mode. Fix performance by ensuring that only a single instance of const finder runs, and only on ttf fonts
Fixes #55370