Skip to content

dart2js: Fold more value numbers onto original variable name #2986

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

Closed
rakudrama opened this issue May 10, 2012 · 1 comment
Closed

dart2js: Fold more value numbers onto original variable name #2986

rakudrama opened this issue May 10, 2012 · 1 comment
Labels
closed-duplicate Closed in favor of an existing report web-dart2js

Comments

@rakudrama
Copy link
Member

I see lots of unnecessary local variables which make the program harder to understand and larger.

In the following example code, char goes all the way to char11.
All of the ssa names are superfluous. Using the root name reduced the code size from 66 lines to 54 and 1969 bytes to 1639 - 17%

Obviously, this only happens in code that has mutable local variables so the global saving would be less, but the code would be more comprehensible.

 _lib11_parseNumber$0: function() {
  if (this._lib11_isToken$1(45) !== true) {
    this._lib11_error$1('Expected number literal');
  }
  var startPos = this.position;
  var char$ = this._lib11_char$0();
  var char0 = char$;
  if (char$ === 45) {
    char0 = this._lib11_nextChar$0();
  }
  if (char0 === 48) {
    var char1 = this._lib11_nextChar$0();
  } else {
    if (this._lib11_isDigit$1(char0) === true) {
      for (var char2 = this._lib11_nextChar$0(); this._lib11_isDigit$1(char2) === true; char2 = char3) {
        char3 = char2;
        char3 = this._lib11_nextChar$0();
      }
      char1 = char2;
    } else {
      this._lib11_error$1('Expected digit when parsing number');
      char1 = char0;
    }
  }
  var char4 = char1;
  var isInt = true;
  if (char1 === 46) {
    var char5 = this._lib11_nextChar$0();
    if (this._lib11_isDigit$1(char5) === true) {
      for (var char6 = this._lib11_nextChar$0(); this._lib11_isDigit$1(char6) === true; char6 = char7) {
        char7 = char6;
        char7 = this._lib11_nextChar$0();
      }
      char4 = char6;
      isInt = false;
    } else {
      this._lib11_error$1('Expected digit following comma');
      char4 = char5;
      isInt = true;
    }
  }
  var isInt0 = isInt;
  if (char4 === 101 || char4 === 69) {
    var char8 = this._lib11_nextChar$0();
    var char9 = char8;
    if (char8 === 45 || char8 === 43) {
      char9 = this._lib11_nextChar$0();
    }
    if (this._lib11_isDigit$1(char9) === true) {
      for (var char10 = this._lib11_nextChar$0(); this._lib11_isDigit$1(char10) === true; char10 = char11) {
        char11 = char10;
        char11 = this._lib11_nextChar$0();
      }
      isInt0 = false;
    } else {
      this._lib11_error$1('Expected digit following 'e' or 'E'');
      isInt0 = isInt;
    }
  }
  var number = $.substring$2(this.json, startPos, this.position);
  if (isInt0) {
    return $.parseInt(number);
  } else {
    return $.parseDouble(number);
  }
 },

@kasperl
Copy link

kasperl commented May 10, 2012

Thanks for the details, Stephen. I think this essentially boils down to us not having liveness analysis implemented yet.


Added Duplicate label.
Marked as being merged into #2577.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report web-dart2js
Projects
None yet
Development

No branches or pull requests

2 participants