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

JS-interop example produces > 670kb .js file #11218

Closed
sethladd opened this issue Jun 11, 2013 · 19 comments
Closed

JS-interop example produces > 670kb .js file #11218

sethladd opened this issue Jun 11, 2013 · 19 comments
Assignees
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Milestone

Comments

@sethladd
Copy link
Contributor

This example:

import 'dart:html';
import 'package:js/js.dart' as js;

void main() {
  var context = js.context;
  js.scoped(() {
    var hug = new js.Proxy(context.Hug);
    var result = hug.embrace(10);
    query('#output').text = result;
  });
}

Calling this JS file:

function Hug(strength) {
  this.strength = strength;
}

Hug.prototype.embrace = function(length) {
  return 'thanks, that was a good hug for ' + length + ' minutes!';
}

Hug.prototype.patBack = function(onDone) {
  onDone('all done');
}

produces a 676kb .js file.

I am using Dart Editor version 0.5.16_r23799

Note: minifying the output code breaks Dart-JS interop.

@sethladd
Copy link
Contributor Author

Attaching the sample app.


Attachment:
dart_js_interop_example.zip (192.08 KB)

@sethladd
Copy link
Contributor Author

@peter-ahe-google
Copy link
Contributor

I assume the problem is that js-interop imports 'dart:mirrors', and that it only uses InstanceMirror.delegate.

Vijay, can you confirm this? If so, I think I know how to fix it.


Set owner to @vsmenon.
Added Waiting label.

@sethladd
Copy link
Contributor Author

FWIW the version of the code w/out the js-interop bits compiles to 95k (unminified).

@sethladd
Copy link
Contributor Author

And, adding the following lines increases size to 686k:

    hug.patBack(new js.Callback.once((msg) {
      query('#output').appendText(' This just in: $msg');
    }));

@sethladd
Copy link
Contributor Author

Removed Type-Enhancement label.
Added Type-Bug label.

@vsmenon
Copy link
Member

vsmenon commented Jun 11, 2013

Yes, it imports dart:mirrors. I believe the only usage is MirrorSystem.getName.

@peter-ahe-google
Copy link
Contributor

Vijay: I'll add an annotation to dart:mirrors called something like: @­EnableTreeShaking. You'll have to use this annotation like this:

@EnableTreeShaking
import 'dart:mirrors';

Does that sound doable?


Set owner to @peter-ahe-google.
Added Accepted label.

@peter-ahe-google
Copy link
Contributor

Added this to the M6 milestone.
Removed Priority-Unassigned label.
Added Priority-High label.

@peter-ahe-google
Copy link
Contributor

Removed Type-Bug label.
Added Type-Defect label.

@sethladd
Copy link
Contributor Author

Thanks for taking a look!

@peter-ahe-google
Copy link
Contributor

Actually, since you only use MirrorSystem.getName, I should be able to detect that and preserve tree-shaking transparently.

@peter-ahe-google
Copy link
Contributor

Oops: I was planning on fixing the problem that because JS-interop imports 'dart:mirrors' tree shaking is disabled. However, Seth hadn't even noticed that. When I compile the example today, the size is 2,6M and it takes almost 12 seconds to compile.

I can fix that regression and bring the size back down to 656K and compile time down to 5 seconds.

I have one further trick in my bag, but that will only get us down to 587K. With minification, it looks like I might be able to bring it down to 323K (this number includes a mapping from minified names to unminified names, so with a little more programming, I should be able to get JS-interop working in minified code).

I don't know if 323K is small enough. If not, it is great that Vijay is working on a leaner alternative to JS-interop.

@peter-ahe-google
Copy link
Contributor

https://codereview.chromium.org/16817002/ provides the first part I described in #­13 (getting the size down to 656K).

@peter-ahe-google
Copy link
Contributor

I plan these further actions on this bug:

  1. Restore global type inference when importing dart:mirrors, but not using problematic features (should bring the size down to 587K).
  2. Get JS-interop working with minification. This should bring the size down to 323K (79K gzipped).
  3. Close this bug as fixed.

Please let me know if you have any concerns about this plan.

@peter-ahe-google
Copy link
Contributor

Added Started label.

@peter-ahe-google
Copy link
Contributor

https://codereview.chromium.org/16830002/ restores global type inference (bringing the size down to 587K).

@peter-ahe-google
Copy link
Contributor

I have a working prototype implementation that seems to work with dart_js_interop_example.zip in minified code. Currently, the size is 327K (80K gzipped), but I should be able shave off a few more Ks.

@peter-ahe-google
Copy link
Contributor

The prototype is here: https://codereview.chromium.org/16851002/

@sethladd sethladd added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js labels Jun 12, 2013
@sethladd sethladd added this to the M6 milestone Jun 12, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants