In the past, performance advice was often presented as anti-patterns, for example “Don’t use for-each” or “Don’t use try-catch”. But developers want to use the latest and greatest features of their language. This leads to the same sort of special-casing that we saw 10 years ago, but for performance reasons instead of behavioral reasons. One place where we really see this ‘specialized’ code appear is in code written for Node.js.
This method avoids regular expressions, splits the first few iterations of a loop, and deliberately stays under a particular character count so that Crankshaft would inline it. Ideally, developers should not have to worry about any of those micro-optimizations, instead they should be able to write something much simpler like the following, and trust that the compiler will do the right thing for performance:
https://github.com/nodejs/node/pull/16869 https://github.com/nodejs/node/pull/16212 https://github.com/nodejs/node/pull/17399
Gurupriyan is a Software Engineer and a technology enthusiast, he’s been working on the field for the last 6 years. Currently focusing on mobile app development and IoT.