Which part of my code is optimized when using Phalcon?

I'm currently testing Phalcon and like the idea behind this framework. I have still some questions about the internals of how Phalcon works. Didn't find more information about that.

As I understand, Phalcon is a PHP-Extension written in C (or newly in Zephir). Of course, the initialization of some other fullstack frameworks will need "a lot" of resources. This overhead is almost not available, when using Phalcon.

What is with my business logic? With my service, model and controller code? What is if the framework overhead is just a small part of my complex application? Will Phalcon be able to optimize this non-Phalcon code as well? Or is this just handled by PHP like any other code?

If the latter is correct, I still can benefit from using single components of Phalcon, like the ORM, in another framework? Because the DB layer of Phalcon has less overhead, for example.

Thank you.

Phalcon doesn't do any optimization of your PHP code. Your PHP code that references PHP constructs is treated just like any other user-space PHP code. The speed increases come in when your code uses PHP constructs.

edited Sep '14

I am new to Phalcon, but this is my understanding:

Phalcon does not optimize your PHP code. The performance boost that you see in Phalcon comes from the fact that the framework itself is implemented in C code as a PHP extension. This is the same way that core PHP code, such as PDO, is implemented. For this reason, the framework functionality implemented by Phalcon is stored in memory and accessed rapidly, bypassing the need to load and parse PHP-based framework code at runtime. Utilizing a class from Phalcon can be thought of in the same fashion as if you were simply utilizing classes built into the PHP core.

This boosts the performance of anything framework-related, which can still be a substantial amount when considering the overhead of large frameworks like Zend.

To answer your question about benefiting from single components of Phalcon, like the ORM - yes, you can benefit from these. Think of it like this - if you had the choice between calling a sorting function that is built into PHP, and that same algorithm implemented in userland PHP code, which would you expect to be more performant? The function built in to PHP of course. This same idea applies to the use of an ORM implemented in userland PHP as compared to the ORM in Phalcon, that is implemented in the same fashion as core PHP code - through C extensions.

Using the Phalcon ORM will not reduce the overhead of the actual database calls of course, but I would still expect to see a performance increase when comparing any Phalcon component to a similar component implemented in userland PHP code.

Please correct me if any of my explanation is inaccurate. Hope this helps!

edited Sep '14

Thank you, @quasipickle and @tylershaw. Your answers are actually what I expected. ;-)

I love to use Symfony2 and Doctrine. And yes, the amount of classes that have to be loaded is huge. My business logical usually is really tiny compared to the framework code. I have to test the real benefit with some project.

Thank you, @quasipickle and @tylershaw. Your answers are actually what I expected. ;-)

I love to use Symfony2 and Doctrine. And yes, the amount of classes that have to be loaded is huge. My business logical usually is really tiny compared to the framework code. I have to test the real benefit with some project.

No problem :). I would imagine if your business logic is rather small compared to the framework, you'd see a decent improvement! Definitely worth testing out.