Memory overhead and C module optimizations

I came across this little benchmark/comparison of some frameworks - it includes Yii:

Yii scores amazingly well in all of those benchmarks!

Except for the last one: memory usage of the framework, where Yii scores worse than any other framework. I wonder why the memory use is so high compared to other frameworks? 3.5 MB compared to e.g. Fuel at 1 MB, is a pretty substantial difference. Is any consideration being given to lowering the memory-footprint of Yii 2.0?

Note that one aspect of this benchmark you can safely ignore, is "framework time per request" - Yii is as fast as the fastest PHP frameworks, and yes, Phalcon is faster, but instead of being taken and impressed by the blue bars, pay attention to the actual numbers: Yii at 1.311 and Phalcon at 0.385.

In my opinion, all this proves, is that maintaining a C codebase is not worth the effort - with less than one millisecond saved per request, there is only a very few, very marginal applications where this would actually matter. Basically, in any application that uses a relational database, one millisecond won’t matter at all, because the bottleneck is the database, and the 1 millisecond of overhead per request is insignificant compared to even a single database PK query and roundtrip.

I can’t see how this type of optimization delivers any significant value, but what it does deliver, is a codebase that is far less accessible to those trying to understand the inner workings of the framework, setting a high barrier for potential framework-contributors, effectively putting a cap on contributions.

For 99% of applications, this optimization won’t matter at all. If I did have to write an application where request overhead was this critical, I would not write that component of the application in PHP in the first-place. I hope Yii does not take that course.

i agree 100% with your opinion.

speed is not the ultimate criteria for picking up a framework and average/optimally Yii sound great when it comes to full analysis for a framework.

For the record, I just had a discussion with folks on the internals php mailing-list, where I argued for an optimization, preventing duplicate storage of the property-names.

It turns out, in php 5.4, this was actually implemented!

Memory overhead in a little benchmark/test-script I posted was one third in 5.4, compared to 5.3. Fantastic!

So basically, starting with 5.4, if you don’t use dynamic properties, php does not maintain a property-hash for the object.

That means you no longer have to compromise on legible property-names ($_m, $_p) in heavily-used classes.

Very nice :slight_smile:


Very interresting point. How about these numbers :

  • Yii :
  • Phalcon :

Wich suggests that Phalcon is almost 3 times faster than Yii…

So if indeed the gain in memory overhead is not huge, the gain in speed definitively is.

The framework seems perfectly extensible with modules and extensions, exactly as Yii, event if those extensions will not be directly integrated into the C module (or will they : So of course any extension will create processing overhead, but no more than in any other "usual" framework (like Yii).

In Yii, we have a “compiled” version : Yiilite. They went the extra mile and compiled their framework into a php module… This does’nt seem totally wrong to me, but I might be mistaking…


2.0 eats less memory and is faster. Can’t say it’s as significant as rewriting everything as PECL though.

At one of latest Moscow conferences a guy from ISP told me that they’re considering implementing a PECL for 1.1 and I think they’ll opensource it in this case. We can do it as well but since it will take significant time we prefer focusing on the framework itself.

I hope that this is the case also without APC enabled.

There already is a huge difference between with or without APC.

A Yii C module would only make the difference between people who are able to configure their server (and install APC and PECL’s) even bigger.

Yii should, IMO, be the fastest framework out of the box - without anything extraneous. :)

Yes, it’s the case w/ and w/o APC. Still I do not recommend using PHP w/o APC since execution time and memory usage is significantly worse.

If only I could afford a VPS, then APC would be the first thing to install.

But it sounds great. I am really looking forward to digging into Yii 2. :)

Yep, so am I!!

Anyway, Yii rules and Yii2 will definitively rock.

Yii is just perfect to me, but I found Phalcon’s approach very interresting, and wondered why no (or few) other framework did the same…


That’s about maintainability of the framework itself. If it’s PECL, you don’t know C and PHP internals, framework devs are busy and you’ve got a core framework error then you’re in trouble. In case with Yii you can fix it yourself.

Yeah, that’s exactly why I’m so glad I work with PHP and open source technologies.

A teammate is using ASP, this archaic monstruosity, and I can bearly understand that he is using DLLs (the .Net framework) without even knowing what’s inside them. He actually can’t know!

I pity the fool…

Well, .net is opensourced.

woah, I like good benchmark, but don’t want to depend on pecl, better rewrite standalone pecl