We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Low performance of ORM

For future project purposes i did a comparision between popular PHP frameworks:

  • Zend 2.3.5

  • Kohana

  • Laravel 5.0.13

  • Phalcon 1.3.4

Environment specification: (same for all frameworks)

  • Nginx v1.6.2

  • PHP-FPM v5.6.7

  • PostgreSQL v9.4.1

In simple "Hello world!" test it kick ass.

pic 1

In raw SQL query is similar to the others frameworks.(Probably DB is the bottleneck) But in scenario using ORM was last.

pic 2

Phalcon code: No ORM

$connection = new \Phalcon\Db\Adapter\Pdo\Postgresql($config); $resultset = $connection->query("SELECT * FROM users"); var_dump($resultset->fetchAll());


$users = Users::find(); var_dump($users->toArray());

Both cases gives same output. Using the ORM is at least 3,5 times less efficient than raw query.

I know what is ORM and i know that its less efficient but dont you think its something wrong with Phalcon ORM impementation?

Could you please submit this code you used to perform the benchmarks?

Currently i dont have access to files till tuesday. But can you specify what code you want?

Are you caching models metadata? Will save 2 queries per table

No, but i didn't use any caching for other frameworks as well.

I think you should, i don't know how big will be the performance impact with, but when with Laravel you are executing one query, like:

SELECT * FROM `users`

In Phalcon 3 queries are made:

SELECT `user`.`id`, `user`.`name`, `user`.`password` /* ... */ FROM `user`

Also you can provide a manual meta data http://docs.phalcon.io/en/latest/reference/models.html#manual-meta-data

edited Apr '15

What you wrote is a simple raw query vs orm queries.

I did performance test of frameworks without additional optimisations. Just like they work out of the box.

Results that i post before was made against phpfpm inside docker container with DB installed on other host.

I made more tests with DB inside same docker container and in different container but on the same host and results was significantly different.

All gathered data and charts:


Chart 1

Chart 2

PS: i double checked all results, and no idea why they vary.