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.
[verse]
I see you there. The one with the brackets.
You're not just a regular variable.
You've got numbers attached, and that makes you unique.
You're the sweetest array in the BASIC fleet.
[chorus]
And I love you to be at the head of the code,
Recalling all of your valuable data.
Like the names and the numbers in my contact list,
So that you can relay them all later.
I'd love you to be here a while.
'Cos I really like your bracketed style.
[break]
[verse]
I hope that you open and close all your brackets.
And the numbers are all within range.
An overflow wouldn't be too great,
So I hope that your values aren't strange.
[chorus]
And I love you to be at the head of the code,
Recalling all of your valuable data.
Like the names and the numbers in my contact list,
So that you can relay them all later.
I'd love you to be here a while.
'Cos I really like your bracketed style.
[break]
[bridge]
When all of the variables are fading away,
Your brackets glisten bright in the moonlight.
As they come close together to encompass your range,
Then I hope that my numbers will come up tonight.
And I feel that your dimensions will feel just right,
Causing your values to slowly ignite.
[break]
[chorus]
And I love you to be at the head of the code,
Recalling all of your valuable data.
Like the names and the numbers in my contact list,
So that you can relay them all later.
I'd love you to be here a while.
'Cos I really like your bracketed style.
[Dave is pacing excitedly behind a counter labeled "SCRUNCHCAKE PRODUCTION LINE." Brian, a nervous new employee, is trying to follow Dave's crazy instructions while fiddling with a mixing paddle.]
Brian: Okay, so ScrunchCakes are basically... a cake with a crunch? And they come in purple because of some secret ingredient?
Dave: Exactly, Brian! And don't forget the sausage.
[Brian looks around, taking in the kitchen's chaos. Machines beep and spin in the background, while various ingredients are scattered around on counters.]
Brian: And the sausage meat comes out of the hole in the tube over there?
Dave: It's not a hole.. It's a mysterious wonderland of Scrunch.
Brian: Looks like a hole in a tube to me.
Dave: Bah, kids.
[Dave shows Brian how to place the sausages into the squared off trays]
Brian: Right, right. So we wrap the meat in batter?
Dave: No, this isn't batter. This isn't a fried sausage roll. This is cake mix. We bake these tasty treats to perfection.
Brian: So where does the crunch come from?
Dave: Crunch?
Brian: They're CrunchCakes, right?
Dave: No, Scrunch. As in Scrunchalicious.
Brian: (confused) Oh.
[The sausages are now coated in cake mix]
Dave: The Scrunch is the secret ingredient.
Brian: I thought purple was the secret ingredient.
Dave: No, purple is only the secret in the Purple ScrunchCakes. But ScrunchCakes can take many forms.
Brian: Can they be crunchy?
Dave: I guess, some of them, maybe. Crunchy ScrunchCakes might be a bit confusing, though.
[Dave helps Brian place the tray of mysterious scrunchiness into one of the many ovens]
Dave: Always shelf 3.
Brian: Could we not use the other shelves?
Dave: No, they don't turn out well on other shelves.
Brian: Isn't that a waste of oven space?
Dave: Don't argue with ScrunchScience.
Brian: Sorry.
[Dave pushes a button on the oven]
Dave: The oven computers have been programmed to beep three times at the exact moment you should remove the ScrunchCakes.
Brian: That's good to know.
Dave: But you MUST open the oven door when the second beep happens, so be at the ready.
Brian: Exactly on the second beep?
Dave: That's the perfect moment for Scrunchtastic flavour.
Brian: And that's the same on any of the varieties?
Dave: Yes, even the Purple ones.
Brian: That seems very specific.
Dave: That's why they call it ScrunchScience.
Brian: [pause] Only you call it that, right?
Dave: So far, yes. I've nearly taught Greenie to call it that, too, though.
Brian: That's the guy organising the magazines, right?
Dave: Yeah. He'll also be working on the till sometimes, I hope. He's not agreed to that, yet.
Brian: Um.. ok.
Dave: So, do you think you can manage this?
Brian: Cover the sausage meat in goop, then shove it in an oven?
Dave: Yes, I know it can be complicated, but we need you to do it as precisely as possible.
Brian: Sure, I could probably manage this.
Views 25, Upvotes 1
Daily Blog
,
Jse
,
Optimising
New games every week!
Places
Archives
Site credits : Jayenkai
(c) Jayenkai 2023 and onwards, RSS feed
6