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

dart2js: Failure to optimize _JsonParser constructor. #7068

Closed
rakudrama opened this issue Nov 30, 2012 · 5 comments
Closed

dart2js: Failure to optimize _JsonParser constructor. #7068

rakudrama opened this issue Nov 30, 2012 · 5 comments
Labels
P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug web-dart2js

Comments

@rakudrama
Copy link
Member

lib/json/json.dart has the following code

class _JsonParser {
  static List<int> tokens;
  _JsonParser(String json)
      : json = json,
        length = json.length {
    if (tokens != null) return;

    // Use a list as jump-table. It is faster than switch and if.
    tokens = new List<int>(LAST_ASCII + 1);
    tokens[TAB] = WHITESPACE;
    tokens[NEW_LINE] = WHITESPACE;
    ... // 25 assignments total
    tokens[CHAR_F] = FALSE_LITERAL;
  }

It compiles to:
_JsonParser$1: function(json) {
  if (!($._JsonParser_tokens == null))
    return;
  $._JsonParser_tokens = $.List_List(126);
  $.indexSet($._JsonParser_tokens, 9, 32);
  $.indexSet($._JsonParser_tokens, 10, 32);
  ...
  $.indexSet($._JsonParser_tokens, 102, 102);
}

In the body of the function, global _JsonParser.tokens is an alias for the list.

If I assign the list to a local (also called tokens), the compiler does a much better job, eliminating all range checks:

_JsonParser$1: function(json) {
  var tokens;
  if (!($._JsonParser_tokens == null))
    return;
  tokens = $.List_List(126);
  tokens[9] = 32;
  tokens[10] = 32;
  ...
  tokens[102] = 102;
  this._JsonParser_tokens = tokens;
}

What would be required to enable the compiler to optimize the original code to the same as the hand-optimized code?

@kasperl
Copy link

kasperl commented May 23, 2013

Added TriageForM5 label.

@kasperl
Copy link

kasperl commented May 28, 2013

Removed TriageForM5 label.

@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.

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@rakudrama
Copy link
Member Author

Obsolete - code has changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants