Today I Learned - Rocky Kev

TIL Micro-optimization

POSTED ON:

TAGS:

I saw this speed test of these Dom selectors.
getElementById vs querySelector vs getElementsByClassName vs querySelectorAll

This was my score.
micro-optimization screenshot

I got really excited to start switching my style.

But then I remembered this quote from Ruben Bridgewater, a member of the Node TSC, whose goal is to push Node forward in every way possible.

The optimizations mentioned in the post are micro-optimizations that reduce the readability of the code and thus the code requires more time to read and to understand which leads to less time to optimize hot code paths. The performance is also just a snapshot of the current version and the very same code might behave very different in the next version due to new engine optimizations.

So remember - focus on readability, not micro-optimization.

[Read his whole comment for even more context] (https://medium.com/@BridgeAR/this-whole-blog-post-is-sadly-very-bad-advice-when-it-comes-to-real-application-performance-7608c05bb93f)


Related TILs

Tagged:

TIL not obsessively trying to be DRY

Quite often, DRY is applied to any duplication, rather than specifically to the duplication of business rules and knowledge. This is often made worse by automated code analysis tools, which will often highlight any duplication as a code smell.

TIL ways to organize eventListeners

Some code spaghetti I made recently was creating a lot of eventListeners for multiple buttons, and then forgot what they all connected to.

TIL Very Efficient Code

This is a great solution. Easy to understand. Executes really fast. No real-time string concatenation. No over-engineering. String appearance is easily customized.