News for hackers. Stuff that matters.
Re:Push ifs up and fors down by simiones on Thursday November 16, 2023 @05:10AM (#38287706)
Honestly, both of these I think are pretty applicable to line-of-business apps as well.

The "push loops down" advice most especially: for any CRUD app, handling creation and updates in bulk when possible will typically save huge amounts of time, much more than in CPU bound use cases. The difference between doing `items.map(insertToDb/postToServer) ` vs doing `insertToDb/postToServer(items)` is going to be orders of magnitude in almost all cases.

I have seen optimizations of this kind take operations from seconds or minutes down to milliseconds. And often the APIs end up cleaner and logs are are much easier to read.

Re:Push ifs up and fors down by atherton33 on Thursday November 16, 2023 @06:51AM (#38288431)
Great point. The n+1 sql queries antipattern comes to mind as a very common "push loops down" application in line of business stuff. Let the db do the work/join.
Re:Push ifs up and fors down by crabmusket on Thursday November 16, 2023 @07:14AM (#38288611)
Oh definitely. I've seen the same kind of benefits. Avoiding 1+n queries is a similar change - push the loop "down" into the database.