Too many runtime checks with sdk types with disabled checked mode

Almost all sdk code from dart:core, dart:collection relies on runtime checks of arguments. For example:

https://github.com/dart-lang/sdk/blob/master/sdk/lib/_internal/js_runtime/lib/js_array.dart#L619

void operator []=(int index, E value) {
    checkMutable('indexed set');
    if (index is! int) throw diagnoseIndexError(this, index);
    if (index >= length || index < 0) throw diagnoseIndexError(this, index);
    JS('void', r'#[#] = #', this, index, value);
  }

variable index is already typed as int, so checking it in runtime for every call should be not necessary. Similar issue with index checking. Ideally I would like to have all type/index checks enabled/disabled with flag so it would be possible to compile dart to performant js code for production after testing.

What do you think about it? Is this in plans for dart 2.0?

Author: Fantashit

1 thought on “Too many runtime checks with sdk types with disabled checked mode

Comments are closed.