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

Implement callbacks with Ruby Fibers

    • Type: Icon: Epic Epic
    • Resolution: Done
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Callbacks
    • None
    • Hide
      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?
      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • Done
    • Callbacks with Fibers
    • 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:
            adviti.mishra@mongodb.com Adviti Mishra (Inactive)
            Reporter:
            jamis.buck@mongodb.com Jamis Buck
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: