TLDR Web Dev · OPINIONS & ADVICE

PUSH IFS UP AND FORS DOWN

matklad.github.io4 min read

Summary from the TLDR Web Dev newsletter

Two rules of thumb for code optimization: "push ifs up" and "push fors down.” "Push ifs up" involves moving conditional logic to the caller function, centralizing control flow, and potentially eliminating redundant checks. "Push fors down" means operating on batches of objects instead of individual items within a loop, improving performance by amortizing startup costs and enabling vectorization.