From bc38bd6964124d907bea4c0ace28939bfb670e79 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 3 Oct 2019 18:36:31 +0000 Subject: [PATCH] Minify ES Modules files After converting the `ui/` folder to ESM, there was a significant performance regression in terms of file size of the `resources.pak`. It turns out that we were not minifying ESM files, but we did do that before with Closure. Update the `copy_devtools_modules` to also invoke rjsmin to minify the JavaScript source code. Before: $ du -h -B K out/Default/resources.pak 12096K out/Default/resources.pak After: $ du -h -B K out/Default/resources.pak 11752K out/Default/resources.pak Before the original CL transforming `ui/` landed: $ du -h -B K out/Default/resources.pak 11860K out/Default/resources.pak This means that after converting `ui/` to ESM, we saved 90KB. We suspect this is because we are no longer transpiling to ES5, but instead serve source ES6. Bug: 1010910 Change-Id: I7dd07ff788d014e9f9a8e25e168c58c010cd00af Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837814 Commit-Queue: Tim Van der Lippe Reviewed-by: Yang Guo Cr-Original-Commit-Position: refs/heads/master@{#702500} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 8d2021d8394b9a248436fb6976070629cdffd961 --- BUILD.gn | 2 +- scripts/build/copy_devtools_modules.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 7c658b9160..b99b3bcd48 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1487,7 +1487,7 @@ action("generate_devtools_grd") { ] grd_files = - all_devtools_modules + generated_applications + + copied_devtools_modules + generated_applications + generated_non_autostart_non_remote_modules + devtools_embedder_scripts + [ "$resources_out_dir/devtools_extension_api.js" ] diff --git a/scripts/build/copy_devtools_modules.py b/scripts/build/copy_devtools_modules.py index 10d9ee2352..a04b9e6525 100755 --- a/scripts/build/copy_devtools_modules.py +++ b/scripts/build/copy_devtools_modules.py @@ -12,6 +12,10 @@ from os.path import join, relpath import shutil import sys +import rjsmin + +from modular_build import read_file, write_file + def main(argv): try: @@ -21,11 +25,13 @@ def main(argv): output_path = argv[output_path_flag_index + 1] devtools_modules = argv[1:input_path_flag_index] except: - print 'Usage: %s module_1 module_2 ... module_N --input_path --output_path ' % argv[0] + print('Usage: %s module_1 module_2 ... module_N --input_path --output_path ' % argv[0]) raise for file_name in devtools_modules: - shutil.copy(join(input_path, file_name), join(output_path, relpath(file_name, 'front_end'))) + file_content = read_file(join(input_path, file_name)) + minified = rjsmin.jsmin(file_content) + write_file(join(output_path, relpath(file_name, 'front_end')), minified) if __name__ == '__main__':