escape_json_string_in_html causes ~23 MB of allocations for 1 MB of JSON #3649
Closed
Description
Describe the bug
I was troubleshooting why my SvelteKit app SSR was consuming a lot of RAM. There's likely other reasons, but this jumped out of the profile:
escape_json_string_in_html
(which is just a wrapper for escape
,
kit/packages/kit/src/utils/escape.js
Line 53 in 59badb5
Reproduction
From a Page's load
function, make a fetch to a 1 MB JSON file, and return it as a prop.
The SSR HTML will end with something like
<script type="application/json" data-type="svelte-data" data-url="/api/graphql" data-body="foo">...</script>
containing said HTML, but creating that HTML apparently takes about 23x the size of the JSON in allocations.
Logs
No response
System Info
System:
OS: Linux 5.15 NixOS 21.11 (Porcupine) 21.11 (Porcupine)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 6.33 GB / 62.61 GB
Container: Yes
Shell: 5.1.8 - /nix/store/xdxv22yb7qnjfyf997r9fx804761z14c-bash-interactive-5.1-p8/bin/bash
Binaries:
Node: 16.13.0 - /nix/store/26lslfmvwyhspppbinznh111fyaxx62z-nodejs-16.13.0/bin/node
npm: 8.1.0 - /nix/store/26lslfmvwyhspppbinznh111fyaxx62z-nodejs-16.13.0/bin/npm
Browsers:
Firefox: 96.0.2
npmPackages:
@sveltejs/adapter-cloudflare-workers: ^1.0.0-next.30 => 1.0.0-next.30
@sveltejs/kit: ^1.0.0-next.239 => 1.0.0-next.239
svelte: ^3.46.1 => 3.46.2
Severity
annoyance
Additional Information
No response