Skip to content

Commit 3f12d07

Browse files
committed
Added note about RFC 8259
1 parent 26c6885 commit 3f12d07

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ throw new SyntaxError() █████████████████
4646

4747
When we receive a 1× payload and decode it we have 2× (UTF-8 if Latin chars) to 3× (UTF-16 if any multi-byte chars) of the payload size in memory — held for microseconds with increased GC pressure.
4848

49-
The payload may be malformed, but to discover this we must incrementally parse it — the job of `JSON.parse`. We would rather skip the intermediate string entirely, identify problems early and protect the application under high load.
49+
The payload may be malformed, but to discover this we must incrementally parse it — the job of `JSON.parse`. We would rather skip the intermediate string entirely, identify problems early and protect the application under high load. And this is totally doable, as according to [RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259#section-8.1), JSON messages MUST be UTF-8
5050

5151
Even if there is only one UTF-16 char in the string, it becomes twice as large in any case. If strings were parsed only one by one and inserted into the resulting structure, it would have MOST of the data UTF-8 and one 1 string UTF-16. This HUGELY improves performance of i18n services.
5252

53+
5354
---
5455

5556
#### [Decoding benchmark](./demo/decoding.mjs) — 4 MB symbols, 100 iterations:

0 commit comments

Comments
 (0)