Improve performance by putting JSON.parse in the bundle?
dumbmatter opened this issue · 1 comments
Based on this article:
Because the JSON grammar is much simpler than JavaScript’s grammar, JSON can be parsed more efficiently than JavaScript.
...
As long as the JSON string is only evaluated once, the JSON.parse approach is much faster compared to the JavaScript object literal, especially for cold loads. A good rule of thumb is to apply this technique for objects of 10 kB or larger — but as always with performance advice, measure the actual impact before making any changes.
Would it make sense to change rollup-plugin-json to return a JSON string wrapped in JSON.parse
for sufficiently large files?
Unless someone convinces me this is a horrible idea, I think I might give it a try, since I have an application that bundles a couple large JSON files with Rollup and I'd like to learn more about Rollup plugins :)
@dumbmatter we're going to be moving this plugin to a new monorepo at rollup/plugins
soon, and a PR to add this feature would certainly be welcome. Please keep an eye out for the move.