propelorm / Propel2

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

Call to initDatabaseMaps initializes too many tables. #1901

Closed profuel closed 2 years ago

profuel commented 2 years ago

Hello everyone!

We've noticed that StandardServiceContainer::initDatabaseMaps call takes 10-100 ms and with a regular process execution life cycle, is mostly wasting time. Regular process uses 1-20 tables, but initializing 300+ ones (for our project) makes very low sense. Any ideas why it's implemented like this? Maybe there's a better approach?

Thanks for your thoughts!

Code: https://github.com/propelorm/Propel2/blob/master/src/Propel/Runtime/ServiceContainer/StandardServiceContainer.php#L261

mringler commented 2 years ago

Hey profuel,

have a look at #1902, I think this might fix your issue. If you can try it out, I'd be interested if it really does make a difference.

profuel commented 2 years ago

Finally, I have some results. Yes, these changes made the function \Propel\Runtime\ServiceContainer\StandardServiceContainer::initDatabaseMaps almost twice faster - 10ms -> 6ms, I have tested with 352 tables. Still wondering why 6ms are there, but it's better than 10 ms :)

dereuromark commented 2 years ago

@profuel Can you approve the PR? Then we can merge it. Unless you have an alternative solution at hand?

mringler commented 2 years ago

Interesting finding, @profuel, thank you for testing! We now avoid instantiating the table classes, but they still need to be loaded since we have to access some static properties. My naive guess is that this is the difference between the time we now save and the time it still costs. Though it might also be the time it takes to read the file with the tables from disk. Still, we might be able to further reduce that time by storing the value of those static properties along with the class name in the configuration. Then again, even 0.01s for 300 tables shouldn't make that much of a difference. Is your application really that constraint in regards to execution time?