New games every week!
🤡-24- Those Pesky Arrays Blog
24th April 2025
Uhoh, am I optimising JSE again!?

-=-=-

One of the slower things in JSE is the array lookups.
I tried all manner of requests, yesterday. All the various chatbots got involved.
A fairly large issue is value range limiting.
Javascript, for whatever the heck reason, doesn't have a "value=Range(myValue, low, high)" function.
I know, right?!
Instead you have to use...
value=Math.min(large, Math.max(low, myValue));
.. or something.. I can never remember, it's so stupidly convoluted.

When working with arrays, I need to get "variable array [value]" as a number between 0 and "array[name][size]", and that means looking up 2 array values, as well as a Math.min and a Math.max, and then also a Math.floor to ensure things are integers.
That's 3 functions and 2 arrays.
And then doing it again over up to 4 possible dimensions of the array.
It's. .. a bit crazy.
And it's one of the main reasons for the slowdown of array lookups.

Instead, then, I asked the chatbots.
Can you come up with a way to do this which only requires single lookups and would be "quicker" than my code. If it's messy, that's ok. I'm looking for speed, not readability.

And the majority of them came up with crazy methods like "Why not place the array values into temporary const's", which causes memory leaks aplenty, and "sure, why not use something simple like "(a = a | 0) < 0 ? 0 : a > b ? b : a;" which.. I'm not sure, if I can manage to count all those a's and b's.. .. There looks to be more than one!!!

ugh.

Back and forth we went, endlessly for a good couple of hours, and in the end nothing managed to speed up the code in any significant way.
.. If anything it slowed it down.

So, \o/yeay\o/, another win for my original epic optimising.
But .. I really wish I could find a way to speed this up.

I'm seriously contemplating reworking how arrays even function to begin with, behind the scenes.
It might just be the best option.

A.I. Corner


Lyrics : By me
Sound Imported : Recorded Probabilities (inst)
> Reveal 🔎

: Download | Suno Link

Alternative version
: Download | Suno Link
Sung by Suno


"Cartoon Derek admires a set of brackets in a line of code, array, values, integers" by DrawThings / Flux

> Reveal 🔎
Views 25, Upvotes 1  
Daily Blog , Jse , Optimising
New games every week!
Site credits : Jayenkai
(c) Jayenkai 2023 and onwards, RSS feed 6

Blog - 🤡-24- Those Pesky Arrays - AGameAWeek