-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esnext.json.parse
is generating (memory-wise) heavier objects
#1354
Comments
It's Sure, we can't implement it in JS as optimized as it can be done in JS engines natively. If you have some proposals how to optimize this polyfill - feel free to open a PR. If performance is critical for you - you could update your Node, it's available natively -> polyfill not installed from Node 21, or just exclude this module from your app if you don't use |
|
Because in your case without |
Sure, that is obvious. The question is, why would the object tree generated by the polyfilled I am not concerned about potential additional memory usage during the Say, you are parsing this JSON |
They have the same tree. Why do you think that's not? One more time - when you call |
Because the memory consumption is higher if that tree was generated with the polyfilled
Again, I get that. This does not explain, why the Something like:
|
Because the native If you want it, you could dig into it and try to optimize it. For example, |
V8 |
esnext.json.parse
is generating (memory-wise) heavier objectsesnext.json.parse
is generating (memory-wise) heavier objects
If you talk about result objects, not about the JSON three, I see only 2 answers: how GC works and descriptors usage -> result objects representation in memory, but that's required for the proper result. In both cases, I don't see how it can be optimized on the |
I played with your example with |
In Node where this feature is available natively, also is a difference in memory usage between cases with |
As I wrote, it's not a bug - it's an issue of optimization for specific engines. As I wrote, if it's interesting for you, feel free to play with internal representations of objects in V8 and open a PR with optimization of this case. |
When using
esnext.json.parse
with areviver
function the deserialized objects are heavier (memory-wise) than the ones that are generated by the non-polyfilledJSON.parse()
function.How to reproduce:
Let the above script run for a while and observe the memory usage and delta when using unmodified
JSON.parse()
, which is something like:When uncomment the first line and using the polyfilled
JSON.parse()
function the output looks like this:You can see that the memory usage is up to 4-5 times larger and growing way quicker.
The text was updated successfully, but these errors were encountered: