webpack-contrib / json-loader

json loader module for webpack - UNMAINTAINED

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

thejonwithnoh opened this issue · comments

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?

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).

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

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!

@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?

@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.