build
build copied to clipboard
update default dart2js flags
Currently the default is to invoke dart2js with --minfiy
. We have started discussions about changing this to -O2
or something else.
Other details we should consider:
- possibly
-O3
is a better default, if not, we should make it easy to discover how to switch between the two - we should also make it easy to discover how to disable minification. Either by making it easy to also switch to
-O1
, or by defaulting the debug configuration to do so?
See also an earlier discussion at https://github.com/dart-lang/sdk/issues/36925
I would be in favor of -O3
by default for release mode, and -O1
for debug mode.
cool - I'll schedule some time to get together with @kevmoo @rakudrama @vsmenon as well, to discuss our options.
For example, we hope to make changes that make more fine grain control on where to omit checks, and one day to specialize code to reduce the cost of checks. If we do all those, a default to -O2
might be pretty good for the average customer.
FWIW, I'm a fan of saying the default is "safe" – and folks can turn the dial to 11 if they like.
But we should discuss...
I think it would be good to clarify more concretely what we mean by "unsafe" for -O3
.
From what I understand it basically comes down to undefined behavior when throwing errors (but not exceptions). Given that those are already indicating real errors in your program, I think that it might not matter much.
I think in order to accomplish this we'll need a separate config for the -O
flag so that it doesn't need to be in dart2js_flags
and we'll need to splice it in intelligently.
I can't remember if we reached a conclusion for this in our offline talks? cc @sigmundch
I believe we concluded to keep it O2 by default and allow to upgrade to O3 with very little configuration.
To ameliorate the concern that the default behavior is not as performant, dart2js will continue to push on three fronts:
- make checks more efficient with a more efficient runtime type representation (this is happening now in order to support NNBD)
- generate code that optimizes away checks if possible (this is not currently under active development, this would be similar to how the VM elides checks when they know statically that the callsite doesn't require them).
- adding local annotations to elide checks in performance critical code. The idea is that well tested core libs and frameworks like angular will use these, and as a result the behavior will be somewhere between O2 and O3.
Semi-related but I am changing the default dev-mode flags to be just --enable-asserts
. If we do change the default optimization level we should do that only in release mode. (see https://github.com/dart-lang/build/pull/2595)