Status: Accepted
Owner: [email protected]
CC: [email protected]
Labels: Type-Bug Priority-Medium

New issue 2435 by [email protected]: Some string operations perform sub-optimally (e.g String.fromCharCode, escape)
http://code.google.com/p/v8/issues/detail?id=2435

Firefox is faster than V8 at the following operations:

// convert a typed array to a js string
function ar2str(uint16arr) {

// break the computation into smaller arrays to avoid browser limits on array size for .apply() call var res = [], i = 0, len = uint16arr.length, MAX_ELEMENTS_PER_CALL = 100000;
  while (i < len) {
res.push(String.fromCharCode.apply(null, uint16arr.subarray(i, i += MAX_ELEMENTS_PER_CALL)));
  }
  var r = res.join("");

  return r;
}

// base64 decode
function b64_to_utf8( str ) {
      return decodeURIComponent(escape(window.atob( str )));
}

A bit of digging shows that fromCharCode for arrays of codes is implemented on the C++ side in Runtime_StringFromCharCodeArray, which is sub-optimal because it uses general-purpose code [JSArray->Get() and String->Set()]. String escaping also uses String->Set(), even though the result is guaranteed to be single-byte. The generic implementation carry a big overhead: simply replacing the JSArray->Get()s with a more specialized ElementsAccessor->Get() call improve performance on ar2str by ~20%.


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to