Get the latest tech news

The intricacies of implementing memoization in Ruby


A long time ago, I wrote a memoization library for Ruby. It was not easy, but I learned a great deal in the process. In this article, I am share these learnings and showing you how deep the memoization rabbit hole goes.

This is a more accurate way than using Time.now, because the monotonic clock is not affected by small shifts that occur e.g. when synchronising with a network time server. In Ruby, method definitions return the mehod name as a symbol, so memo­ize can be stuck in front of the def keyword and the memo­ize :fib line removed: Unfortunately, in the excitement of finding an approach to support memoization for frozen objects, a bigger problem has appeared: memory usage.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of ruby

ruby

Photo of intricacies

intricacies

Photo of memoization

memoization

Related news:

News photo

Litestack: All your data infrastructure, in one Ruby gem

News photo

Implementing a simple object system from scratch in Ruby

News photo

Speeding up Ruby by rewriting C in Ruby