news.volyx.in

The cost of parsing JSON (v8.dev)

543 points by s9w · 2586 days ago · 293 comments on HN

Article summary

The article discusses the cost of parsing JSON and JavaScript, highlighting that JSON parsing is faster due to its simpler grammar. It suggests using JSON.parse for large data objects to improve performance, especially for cold loads. The article also mentions V8's improvements in parse and compile times, and the importance of optimizing download and execution times for web developers. Additionally, it notes that the JSON.parse approach is faster in all major JavaScript engines, not just V8.

Main themes

  • JSON parsing
  • JavaScript performance
  • V8 improvements
  • Optimization techniques
  • Code caching
  • Browser rendering

What commenters say

  • Using JSON.parse can be faster than directly creating JavaScript objects, especially for large data structures.
  • This technique may not be suitable for all use cases and could add unnecessary complexity to the code.
  • The performance benefits of using JSON.parse are not limited to V8 and can be observed in other JavaScript engines as well.
  • There are potential security risks associated with using JSON.parse, such as HTML injection attacks, if user input is not properly sanitized.
  • Some commenters argue that the 2x performance improvement is not worth the added complexity, while others see it as a useful optimization technique for specific use cases.
  • The article's suggestion to use JSON.parse for static objects is seen as a potential way to improve performance, but it requires careful consideration of the trade-offs.
  • The importance of separating data from code is highlighted as a potential benefit of using JSON.parse, regardless of the performance implications.