Skip to content
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

Extension types on JS types generate suboptimal method invocations #55340

Closed
leonsenft opened this issue Mar 29, 2024 · 1 comment
Closed

Extension types on JS types generate suboptimal method invocations #55340

leonsenft opened this issue Mar 29, 2024 · 1 comment
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop

Comments

@leonsenft
Copy link

I just tried rewriting some use of package:js to dart:js_interop and noticed that it generates rather inefficient function invocations:

@JS('signals')
library dart.signals;

@JS('s')
external WritableSignal<T> _signal<T>(ExternalDartReference? initialValue);

WritableSignal<T> signal<T>(T initialValue) =>
    _signal(initialValue?.toExternalReference);

Previously, this snippet:

void main() {
  final x = signal(1);
  ...
}

Produced a direct call to the function s:

main() {
  var x = signals.s(1);
  ...
}

After switching to dart:js_interop, it now generates:

A = {
  callMethod(o, method, args) {
    return o[method].apply(o, args);
  },
  signal(initialValue) {
    var t1 = self.signals;
    return A.callMethod(t1, "s", [initialValue]);
  },
  ...
};

main() {
  var x = A.signal(1);
}

The previous code seems more efficient and smaller–is there a rationale for this change or is it perhaps a regression?

@leonsenft leonsenft added web-js-interop Issues that impact all js interop area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Mar 29, 2024
@ykmnkmi

This comment was marked as resolved.

@srujzs srujzs self-assigned this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. web-js-interop Issues that impact all js interop
Projects
Status: Done
Development

No branches or pull requests

3 participants