this post was submitted on 12 May 2026
878 points (98.7% liked)

memes

21218 readers
2191 users here now

Community rules

1. Be civilNo trolling, bigotry or other insulting / annoying behaviour

2. No politicsThis is non-politics community. For political memes please go to !politicalmemes@lemmy.world

3. No recent repostsCheck for reposts when posting a meme, you can only repost after 1 month

4. No botsNo bots without the express approval of the mods or the admins

5. No Spam/Ads/AI SlopNo advertisements or spam. This is an instance rule and the only way to live. We also consider AI slop to be spam in this community and is subject to removal.

A collection of some classic Lemmy memes for your enjoyment

Sister communities

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] lime@feddit.nu 4 points 1 day ago (14 children)

javascript doesn't have arrays. the backing data structure is a doubly-linked list.

[–] qprimed@lemmy.ml 6 points 1 day ago (12 children)

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.

[–] lime@feddit.nu 4 points 1 day ago (11 children)

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?

[–] thebestaquaman@lemmy.world 1 points 9 hours ago (1 children)

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.

[–] lime@feddit.nu 1 points 7 hours ago (1 children)

can't a jit move things around enough that a linked list could be transformed into a memory-backed array if the access pattern requires it.

[–] thebestaquaman@lemmy.world 1 points 5 hours ago

Sure it can, as long as it retains behaviour according to whatever standard it needs to comply to. My point was rather that I would be very surprised if the actual implementation (at memory level) was a linked list.

load more comments (9 replies)
load more comments (9 replies)
load more comments (10 replies)