Live data from Hacker News

The cost of parsing JSON

v8.dev

221–230 of 308 posts

Re: The cost of parsing JSON

#222

I actually think the previous title of this article which was something about JSON.parse being faster than object instantiation or something like was clearer because in English the cost of something implies that it is a negative, whereas here the performance cost is a benefit relative to another solution with a higher cost. maybe I'm being picky though.

I was expecting something about the extent to which JSON processing in the world contributes to global warming or some such

Re: The cost of parsing JSON

#223
post #208

Earlier quoted context omitted.

JSON.parse won't parse a function call/literal. Direct injection would.

You're right about that, but I don't think you're following the argument. The argument was that there could be a `SimpleObject` that's limited and parses quicker. A `SimpleObject` wouldn't parse a function call, just like JSON.parse. As OP said, "subset of JS Objects". This subset of JS objects wouldn't support function calls.

Don't we already have that, plus a transport medium with JSON?

Re: The cost of parsing JSON

#224

Earlier quoted context omitted.

You're extrapolating quite a bit from a simple comment, which tells me that you'd probably be a poor manager as well. Then again, I'm extrapolating quite a bit as well. Seeing something like JSON.parse throughout the code is definitely a code smell and could decrease the maintainability of the codebase, and that's a very tangible problem. Obviously you shouldn't fire someone over something like this if it's the first…

"We apologize for the fault in the subtitles^Hjavascript. Those responsible have been sacked." "Those responsible for sacking the people who have just been sacked have been sacked" "The directors of the firm hired to continue the credits after the other people had been sacked, wish it to be known that they have just been sacked."

Relevant "The IT Crowd" scene: https://www.youtube.com/watch?v=pGFGD5pj03M

Re: The cost of parsing JSON

#225
Curious! Instantiation by means of the language is actually slower than parsing stuff and instantiating the objects that way. Didn't ever think of that possibility before. Anyway, I understand that JavaScript is much more complicated to parse than bare JSON, but still, that just feels odd. Good read!

Re: The cost of parsing JSON

#226

Earlier quoted context omitted.

Either way it's really more data than object at that point so it's appropriate to store it as JSON. Normally I'd place such data in a different file, but I can imagine that that might not be best for webpages.

> fata you created a noun to describe "fat data" from a typo.

Now I feel bad for fixing the typo...

Re: The cost of parsing JSON

#227

Earlier quoted context omitted.

I've wondered about that with JSON.parse(JSON.stringify(obj)) being the fastest way to deep clone a plain JS object in any JS engine. It always looks dumb when it shows up, but it works well enough and I've seen it described as a best practice by some types of data manipulation libraries.

Would like to know this aswell. I know using spread const clone = {...source}; Is faster than object.assign({},source) And seeing as in this case the source is already a js object it would probably be slow to string and the parse.

Keep in mind that both of those two options are only shallow clones. If you've got any bit of nesting and need a deep clone the code starts to get a lot more complex. In general, in places where I "need" a lot of deep clones I try to use an Immutable library with good reuse/sharing tools, but when you have to deep clone a plain JS object JSON.parse(JSON.stringify(obj)) is incredibly fast in most browsers, despite the fact that you would think string allocation might be a bottle neck.

Re: The cost of parsing JSON

#228
Deliberately provocative conversation piece:

If you're concerned enough about performance, or message passing costs are enough of an overall performance bottleneck, that parsing your messages even 1.7x as fast is worth changing the way you code, you probably shouldn't be using JSON as your message format in the first place.

Re: The cost of parsing JSON

#229
post #216

Earlier quoted context omitted.

Thankfully most other developed country’s healthcare system doesn’t penalise individuals quite so significantly as the broken system you Americans keep voting for. I’m not saying the UK or other European counties have the perfect healthcare systems either but at least we aren’t tied to a job we don’t like because losing our company’s health scheme is too scary to consider.

If you're not paying for it with your money, then you have to pay with your time: public healthcare systems, like those in Europe are known for the long wait times for patients requiring surgery, or other costly procedures. Also, traveling to the US for treatment is still a thing, because new, advanced treatments are developed and first implemented in the US, so all that money spent give you something in return.

Unless you're rich and regularly wipe your ass with $xx,xxx bills, you end up spending your time in the US system too: getting your insurance and care provider to agree with what is covered, what isn't, and how much you have to pay.

Sometimes it takes almost a year to resolve.

BTW, even basic surgeries in the US can have a price tag of close to $100k. I've had to fight off more than one ridiculous bill like this in the last 5 years. If you're talking about medical tourism coming into the US, I can't imagine you're talking about anything but very well off people.

Re: The cost of parsing JSON

#230

I actually think the previous title of this article which was something about JSON.parse being faster than object instantiation or something like was clearer because in English the cost of something implies that it is a negative, whereas here the performance cost is a benefit relative to another solution with a higher cost. maybe I'm being picky though.

I was expecting something about the extent to which JSON processing in the world contributes to global warming or some such

Parsing 1GB of flat JSON data is equal to 1.61 metric cow farts.
Post reply on HN