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

Missed optimizations regarding strings #13114

Closed
peter-ahe-google opened this issue Sep 5, 2013 · 10 comments
Closed

Missed optimizations regarding strings #13114

peter-ahe-google opened this issue Sep 5, 2013 · 10 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@peter-ahe-google
Copy link
Contributor

returnString(x) {
  if (x == new DateTime.now().millisecondsSinceEpoch) return null;
  return 'fisk';
}

main() {
  String x = returnString(1);
  String s = '';
  s += 'y';
  s = '$s$x${returnString(0)}$x';
  print(s);
  s = '$s${returnString(0)}$x';
  print(s);
  print(s);
}

Becomes:

main: function() {
  var x, s;
  x = $.returnString(1);
  s = C.JSString_methods.$add("", "y") + x + $.returnString(0) + x;

Notice that s += "..." isn't optimized as well as s = "$s..."

  $.Primitives_printString(s);
  s = s + $.returnString(0) + x;

Notice that this could be: s += $.returnString(0) + x;

  $.Primitives_printString(s);
  $.Primitives_printString(s);
}

@DartBot
Copy link

DartBot commented Sep 6, 2013

This comment was originally written by ngeoffray@google.com


Fixing the C.JSString_methods.$add here: https://codereview.chromium.org/23496037/.

@kasperl
Copy link

kasperl commented Sep 18, 2013

Added this to the M7 milestone.

@kasperl
Copy link

kasperl commented Sep 23, 2013

Is this fixed?


Removed this from the M7 milestone.
Added this to the Later milestone.

@DartBot
Copy link

DartBot commented Sep 23, 2013

This comment was originally written by ngeoffray@google.com


No, we are not emitting += for s = s + 'foo';

@kasperl
Copy link

kasperl commented Sep 23, 2013

Removed Priority-Unassigned label.
Added Priority-Low label.

@DartBot
Copy link

DartBot commented Dec 19, 2013

This comment was originally written by ngeoffray@google.com


Set owner to @floitschG.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@peter-ahe-google peter-ahe-google added Type-Defect P3 A lower priority bug or feature request web-dart2js labels Aug 4, 2014
@rakudrama
Copy link
Member

The SSA output is now:

    main: function() {
      var x, s;
      x = K.returnString(1);
      s = "y" + H.S(x) + H.S(K.returnString(0)) + H.S(x);
      P.print(s);
      s = s + H.S(K.returnString(0)) + H.S(x);
      P.print(s);
      P.print(s);
    }

Although the SSA backend will convert s = s + "foo" to s += "foo", this is not the same as

s = s + a + b  -->  s += a + b

That requires reassociation of (s + a) + b to s + (a + b), which by itself is harmful since it requires introduction of parentheses.

The CPS output is

    main: function() {
      var x = K.returnString(1), s = "y" + H.S(x) + H.S(K.returnString(0)) + H.S(x);
      P.print(s);
      P.print(s = s + H.S(K.returnString(0)) + H.S(x));
      P.print(s);
    }

Generating += in any context is still TODO.

@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Feb 29, 2016
@floitschG floitschG removed their assignment Aug 11, 2017
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
@rakudrama
Copy link
Member

I'm closing this, since the occasional size benefit from reassociation followed by "+=" is small.
(dart2js does do limited reassociation combined with constant-folding,)

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. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

7 participants