Skip to content

BREAKING CHANGE: Revise default optimization level #1776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/asc.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ exports.libraryPrefix = __getString(assemblyscript.LIBRARY_PREFIX.valueOf());
exports.defaultOptimizeLevel = 3;

/** Default Binaryen shrink level. */
exports.defaultShrinkLevel = 1;
exports.defaultShrinkLevel = 0;

/** Bundled library files. */
exports.libraryFiles = exports.isBundle ? BUNDLE_LIBRARY : (() => { // set up if not a bundle
Expand Down
14 changes: 8 additions & 6 deletions cli/asc.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"description": [
"Optimizes the module. Typical shorthands are:",
"",
" Default optimizations -O / -O3s",
" Default optimizations -O",
" Make a release build -O --noAssert",
" Make a debug build --debug",
" Optimize for speed -O3",
" Optimize for size -O3z --converge",
" Optimize for speed -Ospeed",
" Optimize for size -Osize",
""
],
"type": "b",
Expand Down Expand Up @@ -377,8 +377,8 @@
"description": "Specifies node.js options (CLI only). See: node --help"
},

"-Os": { "value": { "optimize": true, "shrinkLevel": 1 } },
"-Oz": { "value": { "optimize": true, "shrinkLevel": 2 } },
"-Os": { "value": { "optimizeLevel": 0, "shrinkLevel": 1 } },
"-Oz": { "value": { "optimizeLevel": 0, "shrinkLevel": 2 } },
"-O0": { "value": { "optimizeLevel": 0, "shrinkLevel": 0 } },
"-O1": { "value": { "optimizeLevel": 1, "shrinkLevel": 0 } },
"-O2": { "value": { "optimizeLevel": 2, "shrinkLevel": 0 } },
Expand All @@ -390,5 +390,7 @@
"-O0z": { "value": { "optimizeLevel": 0, "shrinkLevel": 2 } },
"-O1z": { "value": { "optimizeLevel": 1, "shrinkLevel": 2 } },
"-O2z": { "value": { "optimizeLevel": 2, "shrinkLevel": 2 } },
"-O3z": { "value": { "optimizeLevel": 3, "shrinkLevel": 2 } }
"-O3z": { "value": { "optimizeLevel": 3, "shrinkLevel": 2 } },
"-Ospeed": { "value": { "optimizeLevel": 3, "shrinkLevel": 0 } },
"-Osize": { "value": { "optimizeLevel": 0, "shrinkLevel": 2, "converge": true } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, does optimizeLevel: 0 really beter than optimizeLevel: 3 for size shrinking?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would assume it depends. If there is a lot that can be inlined for example, it would depend on how well it optimizes away afterwards. If it doesn't, not inlining in the first place may be better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std/array test produces exactly the same binary size with both -O3z and -Oz. The bootstrapped compiler seems to have a difference of a couple bytes: 838.188 with -O3z vs 838.155 with -Oz.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for info!

}
2 changes: 1 addition & 1 deletion tests/asconfig/complicated/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
assert(ASC_OPTIMIZE_LEVEL == 3, "expected optimize level == 3");
assert(ASC_SHRINK_LEVEL == 1, "expected shrink level == 1");
assert(ASC_SHRINK_LEVEL == 0, "expected shrink level == 0");
assert(ASC_FEATURE_SIMD, "expected SIMD enabled");
let size = memory.size();
trace("size", 1, size);
Expand Down
Loading