3

The problem is next - I want to execute simple query (e.g. 10 rows from one table)

In Doctrine this operation takes 0.013752s

Here is DQL:

$q = Doctrine_Query::create()
    ->update('TABLE')
    ->set('FIELD', 1)
    ->where('ID = ?', $id);
$rows = $q->execute();

But when i use plain sql and mysql_query() it takes only 0.003298s

What's wrong? Is Doctrine realy 4x slower?

DrColossos
  • 12,656
  • 3
  • 46
  • 67
John W.
  • 233
  • 1
  • 5
  • 9

1 Answers1

14

John,

Nothing is wrong. Doctrine introduces considerable overhead compared to a straight SQL query. But you gain the convenience of a nice object oriented interface to the database as well as many other benefits. If raw performance is really important then you might not want to use Doctrine. For queries where I need performance over convenience (hundreds of thousands of inserts for example) I use PDO to avoid the overhead that gets introduced by the ORM.

  • 6
    +1: you sacrifice performance for convenience. However, in the test cases that I've seen, Doctrine scales rather well. Just because it's four times slower here doesn't make it four times slower everywhere (in fact, it picks up a lot of speed in bigger data sets). The performance ratio is not linear. – Andrew Sledge Dec 14 '10 at 13:25
  • 1
    Note that this is also not a "problem" of Doctrine or any ORM per se - adding more layers of convenience and abstraction will always come at some performance cost; try doing a "hello world" in Symfony vs. normal PHP! That said, with proper caching and optimization of your indexes, etc you can mitigate the penalties - as another commenter here said, the performance ratio is not linear. – AvatarKava Dec 14 '10 at 13:34
  • 1
    Also note that Doctrine 2 will gain a significant speed up (I read it's 20% faster than Doctrine 1) – DrColossos Dec 15 '10 at 08:22
  • So what I get is there is no way this "issue" can be fixed ? Actually I have a program that uses ajax to load. In plain PHP it takes no more than 40ms through Symfony2 it takes even more than 12s !!! huge difference I suppose – MarGa Apr 11 '13 at 14:57
  • There are many things you can do to speed up your site speed including using several cache layers. Again, if you are writing something small there is no reason to use Doctrine + Symfony, but on a complex system you can save tons of time and headache down the road. – mr1031011 Aug 06 '13 at 00:45