propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 398 forks source link

Improve base performance #1062

Open motin opened 8 years ago

motin commented 8 years ago

According to a recent benchmark, Propel2 does not perform well in the most basic conditions when compared to other popular ORMs:

orm time (ms) memory (KB)
doctrine 77.57 1297.48
propel2 36.83 1178.08
eloquent 25.89 671.20
yii1 14.14 800.39
fuel 9.26 381.07
yii2 7.20 818.16
phalcon 5.66 149.42

The executed code that took almost 37 ms to execute was:

$post = PostQuery::create()->findPk($id);

echo $post->getTitle() . '<br>' . "\n";
$comments = $post->getComments();
echo $comments[0]->getBody() . '<br>' . "\n";

This should be reduced so that Propel 2 remains competitive in simple benchmarks like the one mentioned above.

motin commented 8 years ago

There was an old discussion on the subject (#478), but it did not include the ORMs above that were found faster than Propel.

Another benchmark (https://github.com/Big-Shark/forked-php-orm-benchmark): Results updated 2015-12-08:

PHP CLI 5.6.4 with opcode cache

Library Insert findPk complex hydrate with memory usage time
PDO 49 45 0 33 92 775,264 0.22
LessQL 153 154 0 114 135 5,232,880 0.57
YiiM 211 138 0 79 201 9,961,472 0.67
YiiMWithCache 217 148 0 88 222 9,961,472 0.71
Yii2M 603 338 0 187 252 14,155,776 1.46
Yii2MArrayHydrate 585 327 0 120 220 14,155,776 1.31
Yii2MScalarHydrate 571 321 0 105 102 14,155,776 1.17
Propel20 218 105 0 263 323 10,747,904 0.98
Propel20WithCache 156 68 0 228 261 10,747,904 0.77
Propel20FormatOnDemand 151 67 0 221 264 11,010,048 0.76
DoctrineM 252 280 0 342 193 17,301,504 1.55
DoctrineMWithCache 266 272 0 332 189 17,039,360 1.54
DoctrineMArrayHydrate 263 282 0 226 141 17,825,792 1.35
DoctrineMScalarHydrate 242 292 0 192 123 17,825,792 1.25
DoctrineMWithoutProxies 243 266 0 253 251 16,777,216 1.43
Eloquent 419 254 0 126 218 11,534,336 1.09
EloquentWithoutEvent 380 260 0 124 232 11,534,336 1.06

HHVM CLI 3.10.1 (Corresponding roughly to an up-to-date PHP 5.6)

Library Insert findPk complex hydrate with memory usage time
PDO 54 30 0 37 92 783,680 0.23
LessQL 165 194 0 78 135 10,316,584 0.66
YiiM 333 194 0 81 494 7,267,424 1.33
YiiMWithCache 337 191 0 81 465 7,286,040 1.30
Yii2M 722 272 0 103 175 9,025,400 1.90
Yii2MArrayHydrate 702 273 0 100 165 9,033,272 1.83
Yii2MScalarHydrate 700 291 0 90 70 8,997,160 1.74
Propel20 545 169 0 771 512 9,740,696 2.30
Propel20WithCache 481 135 0 736 485 9,807,688 2.14
Propel20FormatOnDemand 479 128 0 675 463 9,822,696 2.05
DoctrineM 634 647 0 1009 342 19,639,560 5.11
DoctrineMWithCache 624 674 0 1047 339 19,635,128 5.07
DoctrineMArrayHydrate 629 642 0 804 249 18,447,232 4.73
DoctrineMScalarHydrate 618 634 0 747 203 17,366,336 4.55
DoctrineMWithoutProxies 620 629 0 849 357 19,402,032 4.85
Eloquent 589 273 0 98 203 14,652,488 1.53
EloquentWithoutEvent 547 264 0 99 206 14,572,112 1.45

PHP CLI 7.0.0 GA

Library Insert findPk complex hydrate with memory usage time
PDO 38 36 0 33 86 1,720,432 0.20
LessQL 80 80 0 64 80 10,109,208 0.32
YiiM 128 76 0 53 147 6,291,456 0.45
YiiMWithCache 109 73 0 50 150 6,291,456 0.42
Yii2M 246 125 0 75 113 8,388,608 0.64
Yii2MArrayHydrate 233 128 0 63 104 8,388,608 0.60
Yii2MScalarHydrate 235 119 0 50 50 8,388,608 0.51
Propel20 142 74 0 163 190 6,291,456 0.63
Propel20WithCache 86 41 0 124 141 6,291,456 0.44
Propel20FormatOnDemand 85 43 0 118 138 6,291,456 0.44
DoctrineM 120 150 0 189 122 16,777,216 0.97
DoctrineMWithCache 118 146 0 194 112 16,777,216 0.96
DoctrineMArrayHydrate 121 144 0 146 85 16,777,216 0.90
DoctrineMScalarHydrate 118 235 0 183 91 16,777,216 1.01
DoctrineMWithoutProxies 120 151 0 170 190 16,777,216 1.06
Eloquent 209 137 0 84 137 8,388,608 0.65
EloquentWithoutEvent 221 148 0 85 144 8,388,608 0.66
staabm commented 8 years ago

Propel will for sure be perf optimzed but first the featureset itself needs to be completed.

marcj commented 8 years ago

Does anyone know if YII and Eloquent do lazy loading here? https://github.com/kenjis/php-orm-benchmark/blob/master/fuel/app/classes/controller/orm/yii2.php#L37 and https://github.com/kenjis/php-orm-benchmark/blob/master/fuel/app/classes/controller/orm/eloquent.php#L36.

Big-Shark commented 8 years ago

@marcj yes, both

marcj commented 8 years ago

Real lazy loading or are they eager loaded relations through configuration?

Big-Shark commented 8 years ago

@marcj It's really lazy loading

marcj commented 8 years ago

Interesting, then we should look what the hell we're doing currently wrong. :) I guess some caches aren't hit or we load too much eager.

Big-Shark commented 8 years ago

@maikg I think we should not pay attention to this test, it shows the speed initialization propel, and performed only 2 queries

motin commented 8 years ago

@Big-Shark @marcj Agree that is more important to pay attention to the second benchmark, which performs the following:

  1. Mass insertion: Tests model objects and save() operations.
  2. Retrieve By Pk: Tests basic hydration
  3. Complex Query an OR but no hydration: Tests Query parsing
  4. Basic Query with 5 results: Tests hydration and collections
  5. Query with join: Tests join hydration

It gives a better albeit far from perfect idea of how Propel2 performs in real world applications.

dereuromark commented 4 years ago

Is this still relevant, is there anythign that can be done here as action points or can it be closed?