Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize input reading and output writing #21

Merged
merged 5 commits into from
Apr 14, 2024

Conversation

noppa
Copy link
Owner

@noppa noppa commented Mar 18, 2024

This commit aims to fix issue #20.

Use the Emscripten FS.writeFile API for accepting XML input files, instead of the createDataFile and especially the intArrayFromString function. Those were inherited from the parent upstream project, but this writeFile API seems to be simpler to use and performs better.

The bigger fix, though, is in the output side, as pushing one piece of stdout (I guess it was pushing one byte at a time?) caused the stdoutBuffer array to eventually grow so large that it'd throw

RangeError [Error]: Invalid array length

when the output was very big, like when normalizing a big input XML, as described in #20.

Here, too, we can switch to the print/printErr APIs, which seem to be not only simpler but also more resilient to the input size growing.

This commit aims to fix issue #20.

Use the Emscripten FS.writeFile API for accepting XML input files,
instead of the createDataFile and especially the intArrayFromString
function. Those were inherited from the parent upstream project, but
this writeFile API seems to be simpler to use and performs better.

The bigger fix, though, is in the output side, as pushing one piece of
stdout (I guess it was pushing one byte at a time?) caused the
stdoutBuffer array to eventually grow so large that it'd throw

> RangeError [Error]: Invalid array length

when the output was very big, like when normalizing a big input XML, as
described in #20.

Here, too, we can switch to the print/printErr APIs, which seem to be not
only simpler but also more resilient to the input size growing.
Since we will anyway make a potentially breaking change and a major
version bump, I think this is a good time to raise the minimum
officially supported Node.js a bit.

Also, TypeScript tests were failing after upgrading TS version,
because TypeScript no longer supports Node.js < 14.17, and I have no
interest in bending over backwards to make that combination work.
The memory consumption has probably gotten better in PR #21, and the
test was always super flakey anyway, and often passes even without
increasing the memory limit.

Just drop that "should error with out of memory" test altogether.
At least the test still has those initialMemoryPages options, so those
code paths get some coverage, even though there's no actual
counterexample to make sure they are improving things.
@noppa noppa merged commit af5b16b into master Apr 14, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant