You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TextDecoder.decode is superlinear, so text() on a large body is slow #154
TextDecoder.prototype.decode builds its result one character at a time. _decode8 in crates/celld/js/text_encoding.js appends with s += String.fromCharCode(...) per code point, so V8 accumulates a rope with a node
per character. The cost grows faster than the input.
Measured in-Worker, decoding one buffer:
1 MiB 50ms
2 MiB 120ms
4 MiB 693ms
8 MiB 1459ms
Reading the same bytes as a stream is 0-2ms at every one of those sizes, so the
decoder is the whole cost.
Why it matters
Any Worker that calls request.text(), request.json(), response.text() or new TextDecoder().decode(...) on a body of a few megabytes pays this. A JSON
API accepting a 8 MiB document spends over a second inside the decode alone,
and the transient rope is large enough to matter to a node's memory ceiling.
This was found while fixing #152. That issue is fixed by not
decoding a body nobody asked for, which removes the cost from the pass-through
path; a caller that genuinely wants the text still pays it.
Expected
decode should build the string in batches rather than per character, so its
cost is proportional to the input. Decoding a few megabytes should take
milliseconds.
Note
_decode16 and _decodeLegacy in the same file build their results the same
way and are worth checking together.
Activity
v0.3.0
v0.3.0
v0.3.0