4 ms·
> To log a static snapshot with equivalent interactive expansion capability, console.log() would have to do a general deep copy of your object Not necessarily,
by anyfoo 6y ago
> To log a static snapshot with equivalent interactive expansion capability, console.log() would have to do a general deep copy of your object
Not necessarily, and if it did I don't think it would address the actual problem.
console.log could do all the presentation work upfront, right then and there when you log, and provide a collapsed view of that. This would have to include detecting and cycling handles, as it would have to do for a deep copy as you mentioned. The cost would be wasting cycles on this work even if nobody looks at its result.
But where it gets dangerous is if there's any side effects in following the object tree. If visiting for logging e.g. creates nodes, or changes them, or whatever. Arguably "you get what you ask for", but this and the performance hit for generating log output before anyone really looks at it deeply, are probably the main reason things are as they are.
- anyfoo 6y agoErr, handling cycles, not cycling handles. Can't edit anymore, but funny anyway...
- exikyut 6y agoTechnically it's V8/DOM <-> CDP <-> devtools JS -> devtools DOM -> Skia displaylist. In the current status quo, devtools requests values through CDP as you expand the nodes. Based on experiences with using Expand recursively on surprisingly short JSON network responses, I get the impression either the CDP I/O or the JS driving it is quite slow. Or the implementation's just accidentally quadratic. In any case, I get the impression the right solution would be to make V8 execute and retain the deep-copy internally, then forward bits of it over CDP as requested. Hrm, now I'm curious if the underlying mechanics that power the HeapProfiler could be readily repurposed for this. The only fundamental issue, which is likely been the central blocker all along, is representing objects that are cyclic; the implementation would be closer to "object snapshot" than "literal deep copy". (CDP = chrome devtools protocol, ie what gets exposed over --remote-debugging-port.)