Jason Knight
1 min readDec 25, 2022

--

The laugh though being that -- in your test case at least -- the memoization of the transducer is slower -- yes, SLOWER -- than just running the calculation.

Something to be careful of, only apply techniques like this when you need it, and not just out of habit. Remember, JavaScript "arrays" aren't arrays, they're object driven pointered lists, meaning their lookups often have as much if not more overhead than just running what you're trying to cache.

Learned that the hard way 20 years ago on a project where in C "result caching" would have sped things up by a factor of twenty, and in JavaScript resulted in slowing it down by a factor of ten.

If you're using it for long operations like pulling/pushing data from a network request or database, fine... go for it. You use it on simple -- or even most complex -- local operations, you're just bending yourself over the log and squealing like a pig like poor Ned Beatty on a river excursion in the deep south.

--

--

Jason Knight
Jason Knight

Written by Jason Knight

Accessibility and Efficiency Consultant, Web Developer, Musician, and just general pain in the arse

Responses (1)