&
🦊shower thought: if I ever need to modulo a whole number that happens to be a power of 2 (ie 16) instead of doing "x % 16" I could just do "x & 0xF"
&
🦊everyone is assuming this is about C/C++ and saying compiler optimizations make it unnecessary, forgetting we also know javascript, php, gamemaker language, lua, python, GDScript, C#, BASIC, and something else I probably forgot, and not all of those are optimizing this (or anything) for you
@roxy there are a bunch of clever things you can do
computers are really good at multiplying by powers of 2, so if you want to compute 5x faster, you can figure out 4x + x
although you do need to factor in readability. will you be able to tell what you meant in a few months? that's arguably more important than making the code fast
in interpreted languages like lua and gamemaker language and gdscript, I'd guess that x % 16 and x & 0xF take about the same amount of time to run because the overhead of running the not-machine-code is probably significantly higher than a single mathematical processor instruction
&
🦊2A03 assembly for the NES, that's what I forgot. we also know HTML, CSS, SQL, and Dragonspeak, but these are not relevant to this point and I'm just showing off now
&
@ben 🦊 not true, at least for gamemaker. GML can run bitwise math much faster than other operations, so we try to use them whenever we can
@roxy I'm just speaking from my experience with Squirrel where a significant amount of the time spent in my code is the bureaucracy of handling the bytecode
although that might just be because I'm optimizing it so hard in the parts I do control
/Cinny
@ben @roxy yeah in python this is basically correct
x % 16 and x & 0xF are basically the same speed, and x << 2 + x is slightly slower than 5x due to having two additional python-level instruction.
in javascript on firefox (which is optimized) x%16 and x&15 are within margin of error and jsbench says that x<<2+x is slower by 2.1% but i doubt that
like yeah they are “clever” but unlikely to have a performance impact unless you specifically measure the code’s performance, otherwise you’ll likely just spend more time writing “clever” code and trying to understand it again later
@charlotte @roxy yep, only optimize code if you have hard evidence that it needs optimization
&
@ben @charlotte 🦊 which is why we let ashe go wild with her stinky ass brute force code and only really go for optimizations if it's something that takes up a measurable amount of frame time
/Cinny
@ben @roxy also like. multiplication isn’t that slow anymore, even if it’s not optimized away. plenty of cpus, including “slow” ones can do it within only a couple cycles. but ofc actual perf would vary based on other code around it.
x<<2+x could be faster than 2 cycle multiply if the multiplier unit is in use, similarly it could also be slower than it if your instruction sequence is running out of instruction dispatch or retire slots.
similarly adding x to a shifted copy of itself might be one instruction on some ISAs (x86, arm, risc-v with the Zba extension at least for some shift values)
integer divide is still quite slow though
&
@charlotte @ben 🦊 fortunately we haven't been in a position to worry too much about any of this lmao
@roxy getting gut punched by the last option on this list, i’ve not thought about it in years and i still have the numeric codes for commands burned into my brain
(fun fact: i wrote loop and function support for it like 5 years ago which never got released because of the incredible levels of dysfunction)
&
@Ninji 🐿️ we heard about the loop stuff but yea... yea we haven't been on furcadia in ages because it was just a mess and we felt we were putting in all kinds of energy to push up against a wall. all our beekin badges expired and not a single email, not a single person going "hey you guys alright?" really feels like all that was for nothing
@roxy i thought the badge expiry system was turned off at some point but i haven't thought about it in years
i have not been involved with them in 2.5 years and i still have all my badges and i'm still in the github org. i'm fairly certain they haven't revoked my SSH access either but i'm not going to try that lmao
but hey it's okay, i'm sure that once they get the game on facebook, 300 million players will join and all the problems will magically be solved