litejs / json-lite

Fast non-blocking JSON viewer for Chrome and Firefox
196 stars 17 forks source link

Use unzipped document size for auto-format option #34

Closed shravan2x closed 6 years ago

shravan2x commented 6 years ago

The "Auto-format documents" currently seems to use the gzipped document size, which results in it trying to format large documents and fail with Chrome's OOM errors. Since a document could be compressed arbitrarily well, the extension should use the unzipped size instead for this option.

lauriro commented 6 years ago

It actually uses character count by body.textContent.length. With lot of multi-byte content this can differ from actual byte size. In this place I prefer speed over accuracy.

shravan2x commented 6 years ago

In my case it was all ASCII data, should definitely have been < 128. But even a 7MB file continued to be formatted when the limit was set to 1MB. I'll try checking body.textContent.length on that document and report back.

shravan2x commented 6 years ago

I just tried again. Using document.getElementsByTagName("body")[0].textContent.length; gives me 7116555. The Auto-format documents option is set to under 1mb, and it still formats the file.

The reason I felt it was using the content-length is that it was 787564, which is below 1mb.

lauriro commented 6 years ago

good catch, somehow MB constants in code are 100x greater :p