ReactiveCocoa/ReactiveCocoa — pull request #829 by jspahrsummers (2013-09-28 07:23:36+00:00)
Title: Object inlining and instrumentation for RACCompoundDisposable

`RACCompoundDisposable` sees extremely heavy use in RAC, so it's typically one of the biggest sources of memory usage from within the framework. (Though it's worth noting here that the memory used by RAC is often dwarfed by the application itself.)

Turns out the internal `CFArray` is somewhat wasteful when there are only one or two entries, and a not-insignificant amount of time is spent within `CFArray` functions.

So this adds an array of 2 `RACDisposable`s directly into every `RACCompoundDisposable` instance, so it's always preallocated and quicker to access. I found this to perform better than inlining 1 or 0 disposables, though I didn't try 3 (mostly because I don't want to increase instance size that much).

I saved some Instruments traces, but they're super huge, so some numbers will have to do. :trollface:

In my testing against GitHub for Mac:

* Inlining zero disposables (basically the current `master` behavior) resulted in 2.03 - 3.55 MB of memory occupied solely by `RACCompoundDisposable` and its arrays
* Inlining one disposable resulted in 2.08 - 2.45 MB used
* Inlining two disposables resulted in 1.16 - 1.58 MB used

Naturally, there was some variance in the testing, since this was a real world app and it's impossible to perfectly replicate the conditions each time, but those numbers are significant even after that's taken into account.