Node: V8 API: convert Local<Array> into a list of Local<Value>

Created on 19 Apr 2017  Â·  7Comments  Â·  Source: nodejs/node

On last CTC/V8 meeting I think @trevnorris mentioned something to the effect of

Turning Local<Array> into a list of Local<Value> is slow. Possibly due to crossing the API boundary repeatedly. This is often done to extract function arguments from an array before calling the function. Exposing spread call to API would help a lot.

Could I solicit some examples in Node.js source? I'd like to understand the use case here to come up with the best solution. Two that I have in mind:

  • std::vector<Local<Value>> v8::Array::ToList(Local<Array>, int limit). This is more general purpose. We would be able to reduce the overhead of repeatedly crossing the API boundary and use V8's internal mechanisms to iterate an Array faster. It's debatable what to do with holes (prototype chain lookup?) and getters though.
  • v8::Function::SpreadCall(Local<Value> receiver, Local<Array> spread_args). From what I remember from the discussion, this is the primary use of turning an array into a list in the first place. V8 has optimizations in place to make spread calls very fast, so if the use case matches, I'd prefer this over the general purpose solution.

@fhinkel @psmarshall @bmeurer @trevnorris

C++ V8 Engine

Most helpful comment

Got a bit of code for the first item in the issue together @ https://chromium-review.googlesource.com/c/622427

All 7 comments

Just a quick note re using std::vector: https://github.com/nodejs/node/pull/11048#discussion_r98323991 … V8 should probably avoid using that as long as it’s also setting _GLIBCXX_DEBUG in debug mode, the two std::vector implementations aren’t ABI compatible.

Is there anything that can/should be added to this issue? Should it remain open? (I imagine "yes" but asking anyway.)

cc @trevnorris

Got a bit of code for the first item in the issue together @ https://chromium-review.googlesource.com/c/622427

Should this remain open?

I'm doing a bit of issue clean up 🧹. I'm closing this due to inactivity. Please re-open if needed!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmichae3 picture jmichae3  Â·  3Comments

willnwhite picture willnwhite  Â·  3Comments

ksushilmaurya picture ksushilmaurya  Â·  3Comments

Icemic picture Icemic  Â·  3Comments

srl295 picture srl295  Â·  3Comments