Live data from Hacker News

A visual demo of Ruby's lazy enumerator

joyofrails.com

1–10 of 28 posts

Re: A visual demo of Ruby's lazy enumerator

#3
I was expecting a visual comparison towards the end of the article, where you would be able to click a button and both the eager and lazy versions would start executing simultaneously, one displayed next to the other, and you would clearly see that the lazy one completed earlier. This would make it even more obvious how the lazy one is faster.

Nevertheless, this was great.

Re: A visual demo of Ruby's lazy enumerator

#6
Lazy enumeration can also save memory, because you aren’t storing entire collections during intermediate steps, and it works with infinite/unknown size collections. Such as streaming data.

Some examples:

I wrote a utility gem a while ago that lets you lazily intersect, union, etc various potentially infinite streams of data. https://github.com/maxim/enum_utils/

I also used lazy enumeration for traversing the wordmap in my no-RAM static storage gem. https://github.com/maxim/wordmap/

Re: A visual demo of Ruby's lazy enumerator

#7

I was expecting a visual comparison towards the end of the article, where you would be able to click a button and both the eager and lazy versions would start executing simultaneously, one displayed next to the other, and you would clearly see that the lazy one completed earlier. This would make it even more obvious how the lazy one is faster. Nevertheless, this was great.

Thanks for the feedback. I was thinking along those lines but settled on a version that let you toggle between the two. I’ll keep this in mind for next time though.

There are probably a lot of fun variations to explore. Since this post seemed to resonate, I may be motivated to try some more experiments.

Re: A visual demo of Ruby's lazy enumerator

#8
post #5

Really cool visualization and neat to learn about lazy enumeration! Excuse me while I go back through my code and make sure I’m using lazy enumeration wherever I’m iterating over large collections….

This sounds like a similar response I had when learning about stream editors vs text editors. It was one of the killer apps that convinced to become a CLI warrior. Opening up a large text file in Notepad took for ever, but opening the same file in vim was a nothing burger. Then, the same person that showed me that showed me sed/awk/grep, and I was off to the races.

Re: A visual demo of Ruby's lazy enumerator

#10
post #6

Lazy enumeration can also save memory, because you aren’t storing entire collections during intermediate steps, and it works with infinite/unknown size collections. Such as streaming data. Some examples: I wrote a utility gem a while ago that lets you lazily intersect, union, etc various potentially infinite streams of data. https://github.com/maxim/enum_utils/ I also used lazy enumeration for traversing the wordmap…

In the worst case, that must have intermediate space requirements equal to the entire collections, right?
Post reply on HN