-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Callbacks
-
None
-
Not Needed
-
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.
- related to
-
MONGOID-5658 "cascade_callbacks" results in SystemStackError with many documents
- Closed