feat: Reduce build size by enabling assume_function_wrapper build flag#9921
feat: Reduce build size by enabling assume_function_wrapper build flag#9921gonfunko wants to merge 8 commits into
assume_function_wrapper build flag#9921Conversation
Since the chunk export files are source files to Closure Compiler, separate the creation of the former from the invocation of the latter. Specifically: - Rename writeChunkExportFiles to buildChunkExporters. - Invoked as a separate task in the minify series, instead of calling it directly from buildCompiled. - Revert the changes to buildCompiled that made it an async function just so it could call writeChunkExportFiles.
The existing code results in each chunk overwriting the same well-known property ($.__chunkExports__). Since these properties are only expected to be read once, in the same chunk's wrapper's factory function, this isn't strictly wrong - but it made understanding the minified bundles produced by PR #9912 a bit confusing.
Note that some comments have been deleted without replacement; these made statements which are no longer true.
Reorder the new code that generates the chunk exporters, to put it together with (but before) the code that generates the chunk wrappers, since the two are closely coupled.
For consistency with code and docs, call the files that contain code which retrieves the chunks' export objects "chunk exporters", since "chunk exports" better describes the objects being exported.
|
It took a while to remind myself how the code in A few notes about Closure Compiler's behaviour:
To work around this, the LLM proposes adding an extra source file for each chunk to the compiler's input, that imports the chunk and saves the resulting exports (module) object to a well-known location—in this case, on the namespace object that was introduced in #5721. Specifically, for the core chunk, a file import * as exports from `…/core/blockly.js`;
$['__chunkExport__'] = exports;would be inserted into the source files for the chunk, and then the chunk wrapper's factory function would This does indeed work. My main critiques are:
I have therefore taken the liberty of pushing a few additional commits to this PR, which:
I have manually checked to make sure the resulting compiled chunks load locally in the playground. |
The basics
The details
Resolves
--assume_function_wrapperClosure Compiler option #5795$build$srcfrom variable names in compressed chunks #7551Proposed Changes
This is an entirely LLM-generated change. It does seemingly work, and cuts the size of blockly_compressed.js from 1093 KB (216 KB zipped) to 624 KB (176 KB zipped). I split it into two commits; the first is just a formatter run, the second has the actual changes.