Description
While comparing code size between dart2wasm and dart2js I've noticed that the ACX code contains usages of @pragma('dart2js:late:trust')
/ @pragma('dart2js:as:trust')
in the code.
One pattern is to construct a unsafeCast
method that can be used in performance critical code
@pragma('dart2js:tryInline') // Required for next pragma to be effective.
@pragma('dart2js:as:trust') // Omits `as T`.
T unsafeCast<T>(dynamic any) => any as T;
another is to remove checks for late fields for autogenerated code, it globally disables late
checks for a library:
@pragma('dart2js:late:trust')
class X extends ComponentView {
late final field;
@override
void build() {
field = ...;
}
}
While I'm not advocating for introducing these unsafe options in dart2wasm right now, having a way to enable them with a flag, would allow a more eye-to-eye comparison of dart2js and dart2wasm.
First we should make late
smaller in code size (see #60432) then we could evaluate how much size we could safe by having support for similar annotations in dart2wasm.
It may be that this only really gives value in cases like ACX where we have large amounts of autogenerated code.