Skip to content

v8.deserialize is very slow, is it normal? #37199

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

Closed
navegador5 opened this issue Feb 3, 2021 · 3 comments
Closed

v8.deserialize is very slow, is it normal? #37199

navegador5 opened this issue Feb 3, 2021 · 3 comments
Labels
v8 module Issues and PRs related to the "v8" subsystem.

Comments

@navegador5
Copy link

navegador5 commented Feb 3, 2021

  • Version: tested on bth v16.0.0-pre. and v12.18.2
  • Platform: linux
  • Subsystem:ubuntu

What steps will reproduce the bug?

My application sometimes need to keep the undefined/[Circular] when do deepcopy of a object,
so i tried v8.deserialize, it work, but very slow, is this normal or abnormal ?

    const v8 = require("v8")
    
    function deep_copy(o) {
        let buf = v8.serialize(o)
        let nobj = v8.deserialize(buf)
        return(nobj)
    }
    
    
    function orig_dcp(j) {
        return(JSON.parse(JSON.stringify(j)))
    }
    
    function slow_dcp(j) {
        return(deep_copy(j))
    }

    var json = {1:[1,2,3],2:{'a':undefined}}

    function tst(times,f,...args) {
        let start = perf_hooks.performance.nodeTiming.duration
        c= 0
        while(c<times) {f(...args);c=c+1}
        let end = perf_hooks.performance.nodeTiming.duration
        console.log(end-start)
    }
    
> orig_dcp(json)
{ '1': [ 1, 2, 3 ], '2': {} }
>
undefined
> slow_dcp(json)
{ '1': [ 1, 2, 3 ], '2': { a: undefined } }
>
undefined
> tst(50000,orig_dcp,json)
151.65841102600098
undefined
> tst(50000,slow_dcp,json)
2831.4293529987335
undefined
>

How often does it reproduce? Is there a required condition?

always

What is the expected behavior?

I dont know ,just too slow

What do you see instead?

nearly 20 times slow

Additional information

@Lxxyx Lxxyx added the v8 module Issues and PRs related to the "v8" subsystem. label Feb 3, 2021
@BridgeAR
Copy link
Member

BridgeAR commented Jun 2, 2022

@nodejs/v8 PTAL

@navegador5 the algorithm is definitely more complex than JSON and will always require more time. There might still be room for improvement but I did not look at it as Node.js just provides access to the v8 c++ implementation.

@camillobruni
Copy link
Contributor

Would it be possible to have the serialize/stringify and deserialize/parse numbers separately?

@MoLow
Copy link
Member

MoLow commented May 23, 2023

as written in #48137 - node does not do much besides passing the call to v8, so this issue should be reported to v8

@MoLow MoLow closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 module Issues and PRs related to the "v8" subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants