Browse Source

Website note on JSON.stringify() fast path

pull/264/head
Sami Vaarala 10 years ago
parent
commit
cdbb731553
  1. 16
      website/guide/performance.html

16
website/guide/performance.html

@ -456,3 +456,19 @@ function fast(x) {
<p>Use such optimizations only where it matters, because they often reduce <p>Use such optimizations only where it matters, because they often reduce
code readability.</p> code readability.</p>
<h2 id="performance-json-stringify-fastpath">JSON.stringify() fast path</h2>
<p>There's a fast path for <code>JSON.stringify()</code> serialization which
is used when there is no "replacer" argument and no indent. The fast path
assumes that it can serialize the argument value without risking any side
effects (which might mutate the value being serialized), and will fall back
to the slower default algorithm if necessary. This happens at least when:
(1) any object has a <code>.toJSON()</code> property, and (2) any object
property is a getter. See:
<a href="https://github.com/svaarala/duktape/blob/master/tests/ecmascript/test-bi-json-enc-fastpath.js">test-bi-json-enc-fastpath.js</a>
for detailed notes on current limitations; the fast path preconditions and
limitations are very likely to change between Duktape releases.</p>
<p>The fast path is currently not enabled by default. To enable, ensure
<code>DUK_USE_JSON_STRINGIFY_FASTPATH</code> is enabled in your
<code>duk_config.h</code>.</p>

Loading…
Cancel
Save