Re:Functional programming in C++ (2012)
by fulafel on Tuesday December 29, 2020 @02:27AM
(#25567593)
Caching is and will continue to be a core building block of performance in current sw (and hw) systems. And it's a boon when you have a tool to fix one of the two hard problems[1].
[1] The famous quote: "There are only two hard things in Computer Science: cache invalidation and naming things." (attributed to Phil Karlton)
> Especially in garbage-collected languages, what you save in execution time you lose in GC pauses, so the end result is you get neither.
This only applies to GC languages that lack language features support for value types, stack allocation or native heap support.
My example of React.js is the pinnacle of this, all features like hooks, contexts, and concurrent mode only make sense when they estimate the cost of re-executing pure functions to be free, or at least negligible, and yet real-world experience indicates this is definitely not the case.
> One benefit (with respect to the CPU) of pure functions is that they can be cached because you know you'll get the same result for each call (of course, this impacts memory), which you can't guarantee with impure functions. But that's a tradeoff of memory for time.
In my personal experience, I’ve become pretty skeptical of trading memory for execution time. Especially in garbage-collected languages, what you save in execution time you lose in GC pauses, so the end result is you get neither.