I’m writing a new app using Yii Framework, but one of my concerns with Yii has been the impact of using ActiveRecord and ORM on the application performance, so I decided to actually compare how the two perform and the results are quite interesting… Basically you double the performance by using the TableModule/TableDataGateway/DTO pattern instead of ActiveRecord (and that’s for a very simple use case). If you want to know more about what I did and how I blogged about it on my blog at Yii DTO vs Active Record Performance. Moral of the story, if you want performance avoid ActiveRecord/ORM at all costs.
Sorry, I should have mentioned that indeed. Yes, I had schemaCachingDuration set for the db component in the config file when I did the tests, but I didn’t set up caching config as I was using eAccelerator 0.9.6, so presumably caching wasn’t actually working. The reason I used eAccelerator is because it’s like the only caching component that works well with ZendOptimiser and IonCube Loader installed, which is what our host uses, but I’ll give it a try with APC and report back how it goes.
Well I did some further testing and indeed the issue was with schema caching. Once i switched to APC from eAccelerator 0.9.6 and set up cache component with CApcCache in the file, things really picked up. I got to around 80-90 requests per second with both ActiveRecord and TableModule/TableDataGateway/DTO way of doing things. I’ve updated my blog entry to reflect this. So basically make sure you have caching setup correctly as it makes a massive difference. For comparison, with no opcode caching installed I got about 20 requests per second with ActiveRecord… So that’s a 4x difference. Lesson is make sure you have caching enabled and configured correctly if you want to use Yii seriously.
I think other than the performance difference, you should also consider the code maintainability and development speed (anyway, these are the main reasons that you use a framework). AR is not a panacea for everything. However, it does fit very well in the MVC paradigm, and it gives you better OOP experience than table gateway pattern. When performance becomes an issue, exchanging AR for table gateway would be the last thing you want to do because you have many other options to improve the performance without affecting your code maintainability.