Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Browser string optimizations have changed the string concatenation picture.</p> <p>Firefox was the first browser to optimize string concatenation. Beginning with version 1.0, the array technique is actually slower than using the plus operator in all cases. Other browsers have also optimized string concatenation, so Safari, Opera, Chrome, and Internet Explorer 8 also show better performance using the plus operator. Internet Explorer prior to version 8 didn’t have such an optimization, and so the array technique is always faster than the plus operator.</p> <p>— <a href="http://oreilly.com/server-administration/excerpts/even-faster-websites/writing-efficient-javascript.html" rel="noreferrer">Writing Efficient JavaScript: Chapter 7 – Even Faster Websites</a></p> </blockquote> <p>The V8 javascript engine (used in Google Chrome) uses <a href="http://v8.googlecode.com/svn/trunk/src/string.js" rel="noreferrer">this code</a> to do string concatenation:</p> <pre><code>// ECMA-262, section 15.5.4.6 function StringConcat() { if (IS_NULL_OR_UNDEFINED(this) &amp;&amp; !IS_UNDETECTABLE(this)) { throw MakeTypeError("called_on_null_or_undefined", ["String.prototype.concat"]); } var len = %_ArgumentsLength(); var this_as_string = TO_STRING_INLINE(this); if (len === 1) { return this_as_string + %_Arguments(0); } var parts = new InternalArray(len + 1); parts[0] = this_as_string; for (var i = 0; i &lt; len; i++) { var part = %_Arguments(i); parts[i + 1] = TO_STRING_INLINE(part); } return %StringBuilderConcat(parts, len + 1, ""); } </code></pre> <p>So, internally they optimize it by creating an InternalArray (the <code>parts</code> variable), which is then filled. The StringBuilderConcat function is called with these parts. It's fast because the StringBuilderConcat function is some heavily optimized C++ code. It's too long to quote here, but search in the <a href="http://v8.googlecode.com/svn/trunk/src/runtime.cc" rel="noreferrer">runtime.cc</a> file for <code>RUNTIME_FUNCTION(MaybeObject*, Runtime_StringBuilderConcat)</code> to see the code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload