Open everett1992 opened 2 years ago
Just checking my understanding of your example:
require('ion-js')
.load(JSON.stringify(Buffer.alloc(50_000_000).fill('a').toString('base64')))
We're creating a 50MB buffer filled with the ASCII character a
, then converting that binary buffer to a base64-encoded string which will be about 67MB long. The resulting string will not be valid Ion syntax.
For example:
{{ImhlbGxvIHdvcmxkIg==}} // Text Ion blob
"ImhlbGxvIHdvcmxkIg==" // Text Ion string
ImhlbGxvIHdvcmxkIg== // Free-standing base64 data, not a valid Ion value
There is indeed an OOM occurring, but I wanted to see whether this correctness issue affects your use case before diving too deeply on the memory management underlying especially large scalar values.
The base64 string is passed to JSON.stringify so it will be a valid ion string. Ignore Buffer / base64, it can be reproduced with
ion.load(JSON.stringify("a".repeat(50_000_000)))
I can also reproduce by feeding the output of dumpText back to load
const value = "a".repeat(3125000)
const ionText = ion.dumpText(value)
ion.load(ionText) // crashes here
Tho with larger strings dumpText will also crash
const value = "a".repeat(25_000_000)
const ionText = ion.dumpText(value) // crashes here
ion-js crashes when parsing a very large string
JSON.parse parses the string fine.
I'm implementing a npm registry server and the npm publish api POST's a JSON object with the package tarball base64 encoded as a string. Parsing this body with regular JSON.parse causes multiple copies of data
I tested ion-js to see if the reader would save memory.