JRuby

Enumerable missing fiber-related next, rewind, with_index methods

Details

  • Number of attachments :
    0

Description

Enumerable#next, rewind, and with_index may require some trickery to implement. In Ruby 1.9, they use a fiber behind the scenes. If we followed the same course, we would need to use a native thread for any enumerable executing this way, which could be prohibitively expensive. However we could also have special-cased logic for all the core classes, since the details of their enumeration logic are known to us. So for e.g. array, we could simply store a position in the Enumerable state or current thread that is array index-aware. So for many cases we would not need the fiber/thread functionality.

We would need to still detect whether e.g. Array#each has been overridden, so we know to fall back on the slower mechanism. And when we do need to use threading, we should certainly be pooling as much as possible to avoid spinning up a new native thread every time.

Activity

Hide
Charles Oliver Nutter added a comment -

These methods are all there now.

Show
Charles Oliver Nutter added a comment - These methods are all there now.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: