-
Notifications
You must be signed in to change notification settings - Fork 21.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce memory used by ActiveSupport::Callbacks
Previously, callbacks which were shared with subclasses would not share between them the procs generated in Filters::Before and Filters::After. This was also lazily generated so would cause memory growth after an application is booted (and not sharable between workers via CoW). This was because we would rebuild the objects used to invoke the callbacks via CallbackChain#compile, so any difference in the callback chain would result in all of the callback procs being rebuilt. This commit changes before and after callbacks (but not around!) to be shared between all subclasses of where it was defined. This is done by changing Filters::Before and Filters::After to plain classes which respond to call instead of generating procs (which wasn't strictly necessary but was easier to implement, and also results in simpler objects which use less memory). These objects avoid referencing and tied to a specific callback sequence and so can be memoized and reused. This has the most impact on applications with many Controllers, and many callbacks in the ApplicationController (or similar). I also took this opportunity to merge together all the different forms of procs generated (halting, halting_and_conditional, conditional, simple) into one form with if statements. There isn't any significant performance benefit from the specialization previously being done.
- Loading branch information
Showing
1 changed file
with
63 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters