cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.45k stars 160 forks source link

StringBuilder performance #637

Closed neuronsupport closed 3 years ago

neuronsupport commented 3 years ago

The code generated for StringBuilder append makes use of concat method which is a very slow operation. It would make it more agile if we use '+' operator for simple appends which is much faster than concat.

    StringBuilder a=new StringBuilder();
    a.append("Hi");
    a.append(" there");

from

      var a = { str: "", toString: function () { return this.str; } };
                /* append */ (function (sb) { sb.str = sb.str.concat("Hi"); return sb; })(a);
                /* append */ (function (sb) { sb.str = sb.str.concat(" there"); return sb; })(a);

to

      var a = { str: "", toString: function () { return this.str; } };
                /* append */ (function (sb) { sb.str += "Hi"; return sb; })(a);
                /* append */ (function (sb) { sb.str += " there"; return sb; })(a);
lgrignon commented 3 years ago

Hello @norzak Thanks for your suggestions. Sounds like a good idea indeed given this. Would you like to try to add this improvment and PR? I think you will find this in RemoveJavaDependenciesAdapter

neuronsupport commented 3 years ago

pull request https://github.com/cincheo/jsweet/pull/638

lgrignon commented 3 years ago

Perfect, thanks