Report from Dart tree shaker?

40 views
Skip to first unread message

Yegor Jbanov

unread,
Jun 25, 2013, 5:51:33 PM6/25/13
to compil...@dartlang.org
What I need from the report is paths to symbols that were retained after the tree shaking, so I can identify design flaws that cause the code size to increase without a good reason, similar to SOYC in GWT.

Yegor

Peter Ahé

unread,
Jun 25, 2013, 6:03:51 PM6/25/13
to Yegor Jbanov, compil...@dartlang.org
Hi Yegor,

We don't have such a tool yet, but it something that we would like to
provide at some point. See http://dartbug.com/9876.

I think a tool like that might emerge as we start tackling fast
incremental compilations. This requires tracking dependencies more
carefully than we do today, and those dependencies will be the base
for the report you're looking for.

Cheers,
Peter

Peter Ahé

unread,
Jun 26, 2013, 4:51:42 PM6/26/13
to Yegor Jbanov, compil...@dartlang.org
Hi Yegor,

This is about the --output-type=dart option, right? We often call
that "dart2dart". It would be great if you could report these bugs,
but dart2dart is on the back-burner right now, so you'll have to be
patient. Sorry.

Cheers,
Peter


On Wed, Jun 26, 2013 at 7:41 PM, Yegor Jbanov <yjb...@google.com> wrote:
> Thanks, Peter. I think I can live without it in the short term, at least
> until we get to some complicated scenarios. I ran some experiments and found
> behavior that I think should be fixed.
>
> Unused fields are not tree-shaken off, sensitive to type annotations
>
> INPUT:
>
> main() {
> print(new Foo().hello);
> }
>
> class Bar {
> String txt = " World";
> }
>
> class Foo {
> String _hello;
> Bar _world; // never initialized
> String get hello {
> if (_hello == null) {
> _hello = "Hello";
> }
> return _hello;
> }
> String get world {
> if (_world == null) {
> _world = new Bar();
> }
> return _world.txt;
> }
> }
>
> OUTPUT (reformatted):
>
> main(){
> print(new Foo().hello);
> }
>
> class Bar{} // Expected Bar to be gone.
> // However, it will be gone if I change type of _world to
> "var".
> // Nice to see txt tree-shaken off.
>
> class Foo{
> String _hello; // Used, so it stays.
> Bar _world; // Not used, expected to be gone
> String get hello{
> if(_hello==null) {
> _hello="Hello";
> }
> return _hello;
> }
> }
>
> Impact on our app: auto-generated code (e.g.
> https://github.com/google/streamy-dart). We are generating code from a
> number of API discovery documents and that produces a lot of code. We'd like
> to rely on the tree shaker to only pull in code that is actually used. We
> would also like to keep type annotations for code completion (otherwise the
> code generator doesn't add much value).
>
> Zero-effect code not tree-shaken off
>
> INPUT:
>
> main() {
> new Foo(); // Has no effect
> }
>
> class Foo {}
>
> OUTPUT (reformatted):
>
> main(){
> new Foo();
> }
>
> class Foo{}
>
> Impact on our app: again it's mostly auto-generated code. In it we define
> lots of fields, some of which are initialized. However, if a field is not
> used, its initialization is a noop and should be shaken off.
>
> Let me know if any of this makes sense. I'll file bugs.
>
> Thanks,
>
> Yegor

Yegor Jbanov

unread,
Jun 26, 2013, 1:41:33 PM6/26/13
to Peter Ahé, compil...@dartlang.org

Yegor Jbanov

unread,
Jun 27, 2013, 12:57:15 PM6/27/13
to Peter Ahé, compil...@dartlang.org
Yes, I used --output-type=dart option. I didn't know that tree shaking was different depending on --output-type. I'll also check what's inside the JS output.

Reported bugs: #11558#11559

Thanks,

Yegor
Reply all
Reply to author
Forward
0 new messages