anyway, good question. led me to some cursed code.
the ArrayObject in spidermonkey is an interface to either a TypedArrayObject or a SharedArrayObject. those both have an inner ArrayBuffer object, which is a view into ArrayBufferObjectMaybeShared, which contains a refcounted vector of uint8 pointers, regardless of the datatype. soooo all arrays in javascript are… strings?
If I’m understanding you correctly, they’re basically doing the same thing as Python under the hood and using a heap-allocated array (vector) of pointers? If so, that should still be orders of magnitude faster than a linked list.
If their implementation is actually a linked list, colour me shocked. My impression was that JavaScript is “decently fast”. I’ve never even considered writing high-performance code in it, but I’ve heard that the compiler can optimise extremely aggressively, and it’s used so widely that I couldn’t imagine that it had glaring performance issues like what I would expect to see if every array was actually a linked list under the hood.
thanks for the considered reply. didn’t mean to jump all the way down to electrons and sound so flippant.
my claim is that JavaScript arrays are arrays because the spec defines their behavior as such. the implementation details are absolutely interesting from a performance perspective and I was genuinely curious how an internally linked list implementation would actually work, real-world. regardless… almost every interaction I have ever had with a JS programmer has ended in “its strings all the way down”… so… I mean… yes-ish?
loved your poking of the hornets nest in this thread :-)
i was thinking between the linked list and the transistors :)
also, i mean… what you might call an array i might call a vector. js arrays allow elements of different types, so they are by definition not arrays in the traditional sense. them being chars internally does make sense in a gross way.
javascript doesn’t have arrays. the backing data structure is a doubly-linked list.
I’m aware, I added fuel, not peace and love
and the backing for that is linear or page addressed MOS transistors, spinning rust or flippy-round magnets.
do you have a source that indicates mainstream JS engines internally uses a list structure for arrays? I can’t find one.
skipped a few steps there i think.
anyway, good question. led me to some cursed code.
the ArrayObject in spidermonkey is an interface to either a TypedArrayObject or a SharedArrayObject. those both have an inner ArrayBuffer object, which is a view into ArrayBufferObjectMaybeShared, which contains a refcounted vector of uint8 pointers, regardless of the datatype. soooo all arrays in javascript are… strings?
If I’m understanding you correctly, they’re basically doing the same thing as Python under the hood and using a heap-allocated array (vector) of pointers? If so, that should still be orders of magnitude faster than a linked list.
If their implementation is actually a linked list, colour me shocked. My impression was that JavaScript is “decently fast”. I’ve never even considered writing high-performance code in it, but I’ve heard that the compiler can optimise extremely aggressively, and it’s used so widely that I couldn’t imagine that it had glaring performance issues like what I would expect to see if every array was actually a linked list under the hood.
thanks for the considered reply. didn’t mean to jump all the way down to electrons and sound so flippant.
my claim is that JavaScript arrays are arrays because the spec defines their behavior as such. the implementation details are absolutely interesting from a performance perspective and I was genuinely curious how an internally linked list implementation would actually work, real-world. regardless… almost every interaction I have ever had with a JS programmer has ended in “its strings all the way down”… so… I mean… yes-ish?
loved your poking of the hornets nest in this thread :-)
i was thinking between the linked list and the transistors :)
also, i mean… what you might call an array i might call a vector. js arrays allow elements of different types, so they are by definition not arrays in the traditional sense. them being chars internally does make sense in a gross way.
That’s a different kind of array (Float32Array etc.), not the “normal” kind.
i couldn’t actually find any of that in spidermonkey. i was looking in js/vm/arrayobject and its parents, didn’t see any others.
I’m guessing it’s this? https://searchfox.org/firefox-main/source/js/src/builtin/Array.cpp
i did look at that but i started out here: https://searchfox.org/firefox-main/source/js/src/vm/ArrayObject.h because it inherits from NativeObject.
Yes, and since that’s the wrong place I kept looking, and found the link I just sent you
i edited my thing, i did start at array.cpp but only found references to other places so i went digging down the stack.