Skip to content

Commit c47d85b

Browse files
committed
fix(code size): revert previous devMode change to restore size targets
This commit reverts a8d9dbf that introduced a code size regression (16kb gzipped, 63kb minified) in Dart. Effect on the hello world app: gzipped: 105kb -> 89kb minified: 370kb -> 317kb BREAKING CHANGE: - This is very unlikely to be breaking, but I'm still marking just in case. The only change to the user should be that dev mode is driven by Dart's checked mode, like it was in the past.
1 parent 197cf09 commit c47d85b

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

modules/angular2/src/facade/lang.dart

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -257,38 +257,34 @@ bool isJsObject(o) {
257257
return false;
258258
}
259259

260-
bool _forceDevMode = true;
261-
bool _modeLocked = false;
262-
263-
void lockMode() {
264-
_modeLocked = true;
265-
}
266-
267-
@deprecated
268-
void enableDevMode() {
269-
if (_forceDevMode) {
270-
return;
271-
}
272-
if (_modeLocked) {
273-
throw new Exception("Cannot enable dev mode after platform setup.");
274-
}
275-
_forceDevMode = true;
276-
}
277-
278-
void enableProdMode() {
279-
if (_forceDevMode) {
280-
return;
281-
}
282-
if (_modeLocked) {
283-
throw new Exception("Cannot enable prod mode after platform setup.");
284-
}
285-
_forceDevMode = false;
286-
}
287-
260+
// Functions below are noop in Dart. Imperatively controlling dev mode kills
261+
// tree shaking. We should only rely on `assertionsEnabled`.
262+
@Deprecated('Do not use this function. It is for JS only. There is no alternative.')
263+
void lockMode() {}
264+
@Deprecated('Do not use this function. It is for JS only. There is no alternative.')
265+
void enableDevMode() {}
266+
@Deprecated('Do not use this function. It is for JS only. There is no alternative.')
267+
void enableProdMode() {}
268+
269+
/// Use this function to guard debugging code. When Dart is compiled in
270+
/// production mode, the code guarded using this function will be tree
271+
/// shaken away, reducing code size.
272+
///
273+
/// WARNING: DO NOT CHANGE THIS METHOD! This method is designed to have no
274+
/// more AST nodes than the maximum allowed by dart2js to inline it. In
275+
/// addition, the use of `assert` allows the compiler to statically compute
276+
/// the value returned by this function and tree shake conditions guarded by
277+
/// it.
278+
///
279+
/// Example:
280+
///
281+
/// if (assertionsEnabled()) {
282+
/// ...code here is tree shaken away in prod mode...
283+
/// }
288284
bool assertionsEnabled() {
289285
var k = false;
290286
assert((k = true));
291-
return _forceDevMode || k;
287+
return k;
292288
}
293289

294290
// Can't be all uppercase as our transpiler would think it is a special directive...

0 commit comments

Comments
 (0)