Skip to content
This repository was archived by the owner on Aug 20, 2018. It is now read-only.

Usage of "\t" in JSON.stringify makes webpack needlessly slow #31

Closed
thejonwithnoh opened this issue Oct 16, 2016 · 5 comments
Closed

Comments

@thejonwithnoh
Copy link

Should the returned value really be constructed with JSON.stringify(value, undefined, "\t")? Specifically the "\t" could be problematic, and slow down webpack. What's wrong with using something else, such as source for example?

In my project, I'm loading a JSON file that contains a 512x512 matrix of data. In my original file, this takes up 512 lines of text. However, the json-loader's use of JSON.stringify(value, undefined, "\t") is causing this matrix to now consume approximately 262144 lines of text. This seems to be causing webpack to take longer then necessary.

When running a webpack watch using the json-loader as is, it would take each recompile of my project approximately 6 seconds. When replacing the usage of JSON.stringify(value, undefined, "\t") with source or JSON.stringify(value), this is reduced to approximately 1 second.

Perhaps the usage of "\t" could be configured via a query option?

@SpaceK33z
Copy link
Contributor

SpaceK33z commented Oct 16, 2016

I think it makes sense to always use JSON.stringify(value).

@sokra, do you know what the initial reason was to use JSON.stringify(value, undefined, "\t")? It seems that converting the whitespace to tabs is very slow, so perhaps it's better to use JSON.stringify(value).

@sokra
Copy link
Member

sokra commented Oct 16, 2016

To be more readable. But now devtools can reformat code so this is no longer needed.

@thejonwithnoh
Copy link
Author

Thank you so much for the quick response! Any chance of pushing this into an official release on github/npm? Right now I'm including it in my package.json via the commit hash. Thanks again!

@thejonwithnoh
Copy link
Author

@SpaceK33z @sokra: Sorry to be a pest, but I'm not sure if my previous comment was seen after the issue was closed. As per my last comment, since a good portion of the code changed (which given its size and simplicity, any change is somewhat significant), does it warrant a version update and publishing?

@SpaceK33z
Copy link
Contributor

@thejonwithnoh, we will release a new major version around the webpack v2 stable release (which shouldn't be too long). This will also contain #35, which is a breaking change too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants