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
[json] Unable to format large JSON file #79014
Comments
VS Code has issues tokenizing large files. The algorithm is not perfect (nor do I know better alternatives). Try using a computer with a better CPU and/or more RAM, as it may help a bit. If you don't have access to a more powerful PC, maybe all you have to do is wait for a while as it does its work. |
I could not reproduce with generating a JSON using the following: const fs = require('fs');
let obj = {};
for (let i = 0; i <103210;i ++) {
obj[`a${i}`] = 'asdasdadasdasdadasdasdasdasd';
}
fs.writeFileSync('out.json', JSON.stringify(obj)); After running "Format Document" it takes some time, but the JSON gets formatted: |
I am glad you are looking into this. As you can see already in your example it already takes quite some time, and there is no indication that something is happening. That aside in my case I waited for several minutes!!! and nothing happened. I can not post the original JSON that I have because it has a ton of private data but I can share some patterns that I see:
Attached is a generated sample file that not only fails to format but actually crashes VS code |
I consistently get a crash on a 13MB json file. I'm happy to share it directly with anyone working on this, but can't post it publicly. fyi - when I format it using powershell it becomes 120MB in size. Anyone wanting to do similarly in PS can use something like this:
|
Since Visual Studio Code is way too slow and unstable I set on a search for a formatting tool. Found this gem: https://www.jsonformatter.io/ |
This file from #79014 (comment) is working a lot better for me after the changes from #88405 When I run Format, it takes the language service a while to compute the edits, and once the edits are in, it takes the editor around 1s to apply them (264k edits!!), which I think is reasonable: @rjk Can you please share with us a JSON file that reproduces crashing |
I just retested now. Using 1.40.2 it crashed VSCode. Steps:
Using VS Code 1.41.1 with same steps I instead get a message 'Extension host terminated unexpectedly' and there's a 'Javascript heap out of memory' error in devtools. VS Code memory usage got to about 3.8GB. VS Code remains open and usable.
After launching VS Code again I was able to replicate the Extension Host crashing but not the VS Code hang. I haven't tried more than once. I've emailed the file to you now @alexdima |
@aeschli The JSON formatter gives 1_400_000 edits for this particular file. In any case, the editor will merge if more than 1_000 edits are applied into a single edit. But a lot of time and memory is wasted to transmit those 1_400_000 edits, to validate the ranges, etc. Would it be possible to change the JSON formatter to return a single huge change in this case? |
Fixed by ce31ace |
Issue Type: Bug
I have a JSON file that is 5 MB large. When I try to format it nothing happens.
VS Code version: Code 1.36.1 (2213894, 2019-07-08T22:59:35.033Z)
OS version: Windows_NT x64 10.0.17134
The text was updated successfully, but these errors were encountered: