News for hackers. Stuff that matters.
Re:JavaScript performance and a Webkit hotspot by pennig on Monday May 02, 2011 @01:14PM (#2506991)
Looks like WebKit has problems appending to a very long string. The less we can do that the better, so I came up with this solution:

  var dest = 'apple';
  while (dest.length < 100000) {
    var out = '';
    for (var i=dest.length-5, end=i+10; i<end; ++i)
      out += dest[i];
    dest += out;
  }
That brought the time from about 4 seconds to a more respectable 90 msec.
Re:JavaScript performance and a Webkit hotspot by nod on Monday May 02, 2011 @01:37PM (#2507086)
That reduces the number of string appends, sure. But it is well known (see either "The Good Parts" or "High Performance Javascript" that appending strings is quadratic in JavaScript, and that the best way to assemble a large, multipart string is arrayOfStrings.join('');

* And by quadratic I mean "copies the whole string every time" such that an append loop is N^2 while a push+join is linear.

Re:JavaScript performance and a Webkit hotspot by rimantas on Monday May 02, 2011 @03:39PM (#2507525)

  But it is well known (see either "The Good Parts" or "High
  Performance Javascript" that appending strings is quadratic 
  in JavaScript, and that the best way to assemble a large, 
  multipart string is arrayOfStrings.join('');
It's a bit fuzzy now, modern browser optimized that quite a bit, so this mainly applies to older versions of IE.