-
Notifications
You must be signed in to change notification settings - Fork 7
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
Update Dart flute WasmGC workload #53
base: main
Are you sure you want to change the base?
Conversation
This updates the Dart flute benchmark. Apart from using a newer Dart2Wasm compiler this brings two important changes: * The compiler & standard library will now use JavaScript strings as it's only string implementation. It takes advantage of `js-string` builtins if available. We anticipate all browsers adopting the `js-string` builtin proposal and optimize the builtin methods. NOTE: We currently don't *require* the `js-string` builtin to be available. We polyfill the imported methods and we import string constants from the mjs file. The main reason for this is that JavaScriptCore doesn't support `js-string` builtin yet (filed [0]). Once JSC supports the proposal we want to require it as it allows using the much more efficient string constant import mechanism (where string constants are utf8-encoded in the wasm module instead of importing from JS file) [0] https://bugs.webkit.org/show_bug.cgi?id=287402 (Before the compiler used 3 implementations: `{One,Two}ByteString` and `JSString` and copied the strings across the WasmGC<->JS boundary. But now that we get more performant JS strings we prefer using only JS strings due to avoiding the need to copy them across the boundary, working with JS RegExp, ...) * The flute benchmark is now compiled in `-O2` mode that ensures Dart soundness. It will perform runtime type checks as required by the Dart language as well as throw catchable exceptions on out-of-bounds accesses. (Before the benchmark was compiled in `-O4` mode which is unsound Dart, it didn't perform the type checks required by the Dart language specification and didn't perform index checks). We intend to switch Flutter web to also use `-O2` mode.
/cc @kmiller68 @eqrion @danleh |
LGTM I also briefly measured before and after on d8: It's a tiny bit slower now (I assume because of |
What mode does Dart recommend users compile with and why? -O2 or -O4? And is that the mode that most users use? |
The tl;dr
The levels are roughly
The very long version: Dart 1 was an unsound language with optional types (they were ignored at runtime). The switch to Dart 2 made Dart a soundly typed language - the reified generics of Dart 2 require the runtime to perform type checks in order to maintain soundness. (The switch to Dart 3 has introduced nullability in the type system - but this isn't relevant here).
When flutter added a web backend it could only use dart2js and, because type checks weren't optimized yet, they used Though for a variety of reasons we have now strong incentive to a) optimize dart2js type check performance b) switching to For dart2wasm we have optimized those type checks a lot over the last year which made switching to sound Switching the flute benchmark from (**) Measured on D8 as I happen to have numbers for all optimization modes on D8 but not JSC/Shell. |
Cloning into 'wasm_gc_benchmarks'... | ||
cf32ca4 Recompile all benchmarks | ||
f80892d Update Dart SDK, switch wasm to -O2, recompile performance benchmarks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you manually edit this? This is an output file from build.sh
normally so next time someone updates they'll see the old log again.
Is there a build with the bits you're uploading here saved somewhere? Maybe we can update that script to pull from there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This particular line is the abbreviated commit hash and commit message. See hash & commit message from mkustermann/wasm_gc_benchmarks@f80892d
That being said I removed one line from the generated build log
: git clone
outputed something that's to be interpreted by a terminal rather than normal text (git clone
shows this Updating ... (x/y)
where it constantly updates the x/y information of the same line). It wasn't there in the old build.log
and isn't normal text, so I removed that line
@mkustermann Thanks for the detailed explanation! Overall seems reasonable to me (modulo comment on |
@kmiller68 As mentioned on the original commit message, it's not entirely polyfill'able because of the magic utf8-encode imports. I'd actually really make this rely on |
Correction: As I just found out, flutter has already switched to |
What's the magic utf8-encode imports? IIUC, js-string builtins is just a list of host provided imports. Is there some other part I'm missing?
I don't think we can promise any timeline (per Apple policy). That said, happy to go either way you decide. |
Specifically I'm referring to this part of the specification:
This is a really useful mechanism
The main thing we care about is that this will be included in the next version of JetStream. Is there a timeline when the next version may be published? |
@mkustermann Thanks for that explanation, that makes sense to me. |
This updates the Dart flute benchmark. Apart from using a newer Dart2Wasm compiler this brings two important changes:
The compiler & standard library will now use JavaScript strings as it's only string implementation. It takes advantage of
js-string
builtins if available.We anticipate all browsers adopting the
js-string
builtin proposal and optimize the builtin methods.NOTE: We currently don't require the
js-string
builtin to be available. We polyfill the imported methods and we import string constants from the mjs file. The main reason for this is that JavaScriptCore doesn't supportjs-string
builtin yet (filed [0]). Once JSC supports the proposal we want to require it as it allows using the much more efficient string constant import mechanism (where string constants are utf8-encoded in the wasm module instead of importing from JS file)[0] https://bugs.webkit.org/show_bug.cgi?id=287402
(Before the compiler used 3 implementations:
{One,Two}ByteString
andJSString
and copied the strings across the WasmGC<->JS boundary. But now that we get more performant JS strings we prefer using only JS strings due to avoiding the need to copy them across the boundary, working with JS RegExp, ...)The flute benchmark is now compiled in
-O2
mode that ensures Dart soundness. It will perform runtime type checks as required by the Dart language as well as throw catchable exceptions on out-of-bounds accesses.(Before the benchmark was compiled in
-O4
mode which is unsound Dart, it didn't perform the type checks required by the Dart language specification and didn't perform index checks).