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

perf: improved data serialization with stream #10

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

wendraw
Copy link
Contributor

@wendraw wendraw commented May 27, 2024

Description

As discussed before #9 (comment) . dump data returns a huge object, when we serialize the object with JSON.stringify, Node.js throws OOM or stack overflow.

so, add msgpackr to serialize huge object with stream and buffer to resolve this problem.

Linked Issues

Additional context

@antfu
Copy link
Owner

antfu commented May 28, 2024

Thanks! That's interesting, but I am afraid that it will introduce difficulties for other viewers to load that data (for example, instead I might write a script to consume that data instead of using the viewer).

I wonder if there is a better streaming solution to JSON format instead?

@wendraw wendraw changed the title perf: add msgpackr for improved data serialization perf: improved data serialization with stream May 29, 2024
@wendraw
Copy link
Contributor Author

wendraw commented May 29, 2024

Thanks! That's interesting, but I am afraid that it will introduce difficulties for other viewers to load that data (for example, instead I might write a script to consume that data instead of using the viewer).

I wonder if there is a better streaming solution to JSON format instead?

ok, I got your meaning.

I replaced msgpackr with WriteStream, then manual recursive handling of huge objects. and then OOM problem was resolved.

And the test/fixtures/vite can work very well! it has 931971 lines.
image

BUT, the command node --import regex-doctor/register ./node_modules/nuxi/bin/nuxi.mjs build doesn't work with the stream. the result is that the output.json content is empty.

So, I create a new script build:doctor-script to exec build command, and then it can work. BUT, it only tracks small data. it only has 4784 lines.
image

In summary, the performance problem seems to be solved by WriteStream.

I don't know why the WriteStream doesn't work in the node command. If you have a direct reason, please tell me.

@wendraw wendraw closed this May 30, 2024
@wendraw wendraw reopened this May 30, 2024
@wendraw
Copy link
Contributor Author

wendraw commented May 30, 2024

🚀with the new code, I had to handle the problem.

The command node --import regex-doctor/register ./node_modules/nuxi/bin/nuxi.mjs build doesn't work with the stream.

image

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.

2 participants