this post was submitted on 22 Mar 2025
21 points (100.0% liked)
Programming
19139 readers
74 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
In script.js, l.149ff:
The term
topLeftX + column * this.height
can be rewritten astopLeftX * this.height + column * this.height
. The first term of this is a constant and can be extracted into a variableconst verticalOffset = topLeftX * this.height
.Similarly,
topLeftY + row
doesn’t need to be recomputed in every iteration of the inner for loop. Move it out into the outer for loop.Also notice that the variable part,
column * this.height
is all the integer multiples ofthis.height
. Therefore, instead of a multiplication, you can simply addthis.height
to a running total. Sums should be faster than multiplications.With these three changes you get [Edit: I think I made mistakes during the replacements.]
Ah yes I see! That should offer some improvement given the number of times it’s called— also see I’m used to swift so I keep using let when I should probably use const— thanks I’ll give it a try and let you know what happens!