News for hackers. Stuff that matters.
Re:I made JSON.parse() 2x faster by Waterluvian on Saturday March 04, 2023 @05:54PM (#35025319)
This is delightful!

Maybe next you can make the object spread operator faster ;). I was recently bitten by it in a hot loop, thinking it was generally syntactic sugar. Turns out that if I know all the property names in an object, it’s far far faster to just assign them all manually.

Re:I made JSON.parse() 2x faster by radex on Saturday March 04, 2023 @06:01PM (#35025377)
That could be interesting! Curious: are you taking about a plain object spread, or are you talking about JSX spreads? The latter has more overhead. Also, which JS engine?

BTW. I recently measured the spread operator in a microbenchmark. Interestingly, while the native spread was faster on Hermes and JSC, it was slower on V8/Chrome, and it's faster there to use `Object.assign()`, i.e.:

['@babel/plugin-proposal-object-rest-spread', { loose: true, useBuiltIns: true }]

Re:I made JSON.parse() 2x faster by v0idzer0 on Saturday March 04, 2023 @07:08PM (#35025797)
Doesn’t assigning properties behave differently? Spread creates a new object while assigning reuses the existing. Unless you mean creating a new object and then assigning the properties. I’d be surprised if that performed worse though. Also curious if the properties are primitives?
Re:I made JSON.parse() 2x faster by pcthrowaway on Saturday March 04, 2023 @08:24PM (#35026203)
I wonder if you can just configure this as part of the compile step with typescript, when the object you're spreading has a known type