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

Spike: Consider implementing callbacks with Ruby Fibers

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 9.0.1
    • Affects Version/s: None
    • Component/s: Callbacks
    • None
    • Not Needed
    • 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?

      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:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: