Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5722

Implement callbacks with Ruby Fibers

    • Type: Icon: Epic Epic
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Callbacks
    • Labels:
      None
    • 0
    • 0
    • 0
    • 100

      The current implementation of callbacks in Mongoid suffers from potentially problematic callstack depths when dealing with large numbers of embedded children (see MONGOID-5658). These callstack trees go so deep because of the need to support "around" callbacks, and go deep even when the embedded children do not declare any around callbacks.

      One possible solution to this is to reimplement the callback system using ruby's Fiber feature. This allows even around callbacks to be flattened into a linear callback chain, removing the need for recursive callstacks.

      I've attached a proof-of-concept that demonstrates how Fibers can be used to implement before, after, and around callbacks, which allows us to unify the implementations as well. This could lead to cleaner code, callbacks that are easier to reason about, and generally making Mongoid easier to maintain.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jamis.buck@mongodb.com Jamis Buck
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: