I don't think is really that costly. The table we need to maintain might be 'big', but it's full of references, not a copy of AR object itself.
I did some modifications on CActiveRecord and CActiveFinder to implement this, will post them on yii google gode page in just a few secs.
Ran test on quite a big PostgreSQL table table, 33.000 rows and 36 columns.
*** SVN 1.0 branch, umodified ***
Mem: 199423 KB, Real: 297728 KB
Time: 36.679 sec
*** With the patches that implement the global storage ***
Mem: 199444 KB, Real: 297728 KB
Time: 35.659 sec
Mem = memory_get_usage()/1024, Real = memory_get_usage(true).
Now, It wasn't s huge table, but working with 33.000 Active Records in one go it not a common situation.
Results: Global caching used 21 KB more of memory, but it was about 1 sec quicker.
I didn't time the eager loading, but would expect similar results.
I'd vote for this method to be implemented into Yii
>For objects fetched by eager loading, they are not duplicated, though.
Not within the same 'node', but something like:
$all = $MyAR->model()->with('order', 'manager')->findAll();
would duplicate a the same $person if they were relations both in order and manager.
$myAr->order->person and $myArr->manager->person could be referencing the same person, but the objects would be duplicated in memory.
This new method of caching objects would also prevent that.
See http://code.google.c…s/detail?id=289 for patch.