4 ms·
Interfaces you supply will necessarily constrain implementation details. So it winds up mattering. Passing a function to a function is a bunch of indirection
by jbooth 10y ago
Interfaces you supply will necessarily constrain implementation details. So it winds up mattering.
Passing a function to a function is a bunch of indirection and extra stack frames(!) compared to updating very small, memory aligned mutable state in-line with the work you're doing. It's even worse with closures where you're creating anonymous data structures and passing them around. You can read up on TLBs and the speed difference between L1 cache and main memory if you'd like to know more.
You might not care about the above if it's more 'beautiful' to you, but it's vastly, vastly less performant.
- rtpg 10y agothat's if you implement it as a function :) You could totally implement these things as compile-time macros, or do many different optimisation passes, or so many other things.
- AstralStorm 10y agoThe old school of algorithm developers used to introduce hard, explicitly verified preconditions and postconditions. Typically this is done in C and C++ using assertions. In general, any dependence on external mutable state should be asserted or otherwise verified. Those checks can be disabled for performance later. Meshes very well with actual tests too.