-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[js_interop/dart2js] Constant fold string literals .toJS
in dart2js
#56045
Comments
Labels: |
Constant-folding of final top-level/static variables is mostly done by CFE. We could do something more limited if this is a popular code pattern./ |
The reason I used that pattern in a benchmark is because on dart2wasm this is not a NOP and we'd do the key conversion every single time we do a map lookup. So it makes sense to hoist it there to top-level which then regresses dart2js. If we recognize this specially in dart2wasm compiler (see #56046) then using the pattern inline in code (rather than top-levels) would not be needed. Though any 3rd party user may also think it's more efficient to cache in a top level instead of executing every time - and it would be worse performance. So I think maybe it's a good idea to do this optimization regardless. |
The following example
compiles (with
dart compile js --no-minify -O4 -o repro.js repro.dart
) to:When instead manually inlining this in dart to
then this becomes
/cc @srujzs @rakudrama
The text was updated successfully, but these errors were encountered: