JSON formatted text file makes CPU jump to 100%

0

I'm editing a JSON formatted text file in Mac OS X Mountain Lion (10.8.2) on a 2.3 GHz Intel Core i7 with 8 GB of RAM.

The file is approx. 3 MB large so it's not very big. Anyhow this is making both TextEdit and Coda 2 to use 100% CPU. I really do not understand what is causing this behavior.

File in question: download link

Peter Warbo

Posted 2013-02-26T14:44:02.193

Reputation: 103

Are there really, really long lines in that text? Could be the cause. – Desmond Hume – 2013-02-26T14:55:19.503

No not at all, this is very interesting, I just tried open the file with TextWrangler and the same issue, 100%... maybe I should upload the file and you can have a look at it... – Peter Warbo – 2013-02-26T15:08:39.497

Okay, go ahead. – Desmond Hume – 2013-02-26T15:17:37.393

Added download link in question... – Peter Warbo – 2013-02-26T15:31:50.793

Answers

3

As I expected, your JSON file contains an extremely long line at the end due to some sort of corruption. The line mostly consists of white spaces.

Desmond Hume

Posted 2013-02-26T14:44:02.193

Reputation: 1 870

Aha, how did you spot it? But I don't understand how whitespace can make the CPU go 100%? Btw, how are you using Amazon to share files? :) – Peter Warbo – 2013-02-26T16:13:56.577

It could be that most text rendering engines (or even text editors) are optimized in a way that prevents them from fast digesting/displaying very long lines. As for Amazon, I was using Amazon S3 service, here are the links Amazon S3, AWS Free Usage Tier.

– Desmond Hume – 2013-02-26T16:28:17.957

Btw how did you "clean" the file? – Peter Warbo – 2013-02-27T09:36:02.183

@PeterWarbo Well, I opened it in Sublime Text, deleted that massive whitespace at the end, removed trailing spaces from every line using regular expressions (trailing spaces are redundant in JSON), and added one missing ] at the end. – Desmond Hume – 2013-02-27T10:19:33.813

Ah Sublime Text worked beautiful, all other text editors I've tried choked on the file for some reason, what does that regex look like to delete trailing whitespace? (but keeping newlines) – Peter Warbo – 2013-02-27T10:34:02.853

@PeterWarbo Replace \s+\n with \n. – Desmond Hume – 2013-02-27T16:57:54.877

0

Try to turn off the coda syntax highlighting feature in edit menu, because the coda try to keep syntax highlighting and the file is too big for this. I think.

Steve Butabi

Posted 2013-02-26T14:44:02.193

Reputation: 61