Closed
Bug 1002653
Opened 11 years ago
Closed 2 years ago
Add a way to create JS arrays with a given capacity via a single API call and then quickly fill their buffer
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: bzbarsky, Unassigned)
Details
Right now there are two ways to creating an array and then filling it with a bunch of Values that I have in the form of C++ objects:
1) The fast but memory-wasteful way: Create a AutoValueVector, fill it in with my Values, call JS_NewArrayObject. This temporarily forces me to have two copies of the vector in memory, which can trigger OOM on low-memory devices for large arrays. This is the approach ToJSValue takes right now.
2) The slower but non-wasteful way: JS_NewArrayObject with the right length, then JS_DefineElement calls for each element. This avoids two copies of the array data in memory, but requires some pretty nasty slow stuff for each element, which sucks for small arrays. This is the approach bindings take right now for sequence return values.
It would be nice to have something that handles the best of both worlds.
The issues on the JS engine side are barriers and TI stuff, as far as I understand.
terrence suggested just doing one or the other approach based on the length, with some cutoff (maybe the default size of AutoValueVector) as the length where we switch from double-allocating to slower per-element behavior. We could try this as a workaround, but it leads to pretty annoying code that likely gets inlined various places... If we can figure out something better, that would rock.
Comment 1•11 years ago
|
||
The self-hosting infrastructure has support for eagerly allocating a dense array through js::intrinsic_NewDenseArray, and then filling it with values through js::intrinsic_UnsafePutElements (both in vm/SelfHosting.cpp). Maybe something like this can be exposed via JSAPI?
| Reporter | ||
Comment 2•11 years ago
|
||
Looking at intrinsic_UnsafePutElements, it just comes down to setDenseElementWithType in the case I care about.
I'd love an API for calling setDenseElementWithType directly. Doubly so if it can be inlined. ;)
Of course I'd also need an API for making such a call safe.
| Reporter | ||
Comment 3•11 years ago
|
||
Eric, this would also be somewhat helpful for bindings performance, for sequence return values.
Flags: needinfo?(efaustbmo)
Updated•3 years ago
|
Severity: normal → S3
Comment 4•3 years ago
|
||
Clear a needinfo that is pending on an inactive user.
Inactive users most likely will not respond; if the missing information is essential and cannot be collected another way, the bug maybe should be closed as INCOMPLETE.
For more information, please visit auto_nag documentation.
Flags: needinfo?(efaustbmo)
Comment 5•2 years ago
|
||
Given the initial description explaining that the problem is on the barrier and TI, I presume we can mark this issue as works-for-me given that TI is no more.
Feel free to re-open in case I am wrong.
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•