indyelixir / fibonacci

An Elixir interface to the Fibonacci series.
1 stars 1 forks source link

Caching old results #4

Open janxious opened 8 years ago

janxious commented 8 years ago

If you run series more than once, all the numbers you've spent time computing in the past one must compute again.

I can imagine caching all the numbers, but that is space inefficient. Probably storing 2 sequential numbers on some logarithmic numeric scale would allow one to skip generation for large numbers if you wanted to know a value at a certain point. ETS/GenServer/Agent are the likely candidates for storing this cache data. This is purely a performance hack, but one can imagine warming up the cache and then having sub-µs generation times afterward for very large sequences.

Thoughts?

stevegrossi commented 8 years ago

It sounds like a great idea, not just for performance but as an educational illustration of using OTP in Elixir libraries, which I had to leave out of my talk due to time.