For large JSON-compatible objects, JSON.parse is faster than JS object literals.
True for all browser JavaScript engines!
Speed-ups from 1.2× to 2×
My #ChromiumDevSummit lightning talk explains why:https://www.youtube.com/watch?v=ff4fgQxPaO0 …
-
-
The trade-off space here is pretty large - with code caching specifically, you save on parsing but you pay for deserialisation of the strings and object boilerplates. For multiple initialisations it still makes sense, but for a single one it's a bit of a toss up.
-
Indeed, if you evaluate a literal many times in the same run of a program, that's faster than JSON.parse. The advice mainly applies to larger config objects. (Even there it depends whether you have large constant strings or complex objects.) "It depends" isn't as catchy :-)
- Još 3 druga odgovora
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.