This code :
With the first and last SELECT queries as:
- Last 100 SELECT queries take more than 14 seconds to execute! (table is empty)
- Filed as a bug because a real life scenario caused major performance leak and memory usage when attempting to do 6000 calls to find().
- Calls to SingleTablePersister::_getSelectColumnListSQL() do not use BasicEntityPersister::$_selectColumnListSql
- This generates a lot of calls to _getSelectColumnSQL() (See last SELECT query with alias counter up to 16800)
- This generates a lot of calls to addFieldResult()
- And this fills up pretty quickly ResultSetMapping::$declaringClasses
- To finally put a huge burden on SimpleObjectHydrator::_prepare() where it iterates on $this->_rsm->declaringClasses and calls getClassMetadata() for each one!
- And all that, including _prepare(), is executed for each SELECT, even though none of them find any result (the table is empty).
I fixed my project using the following patch:
I do not know if this patch is safe for everybody.
But, well, you can easily reproduce the problem and analyze the phenomenon using a profiler on the sample code provided.
Thanks for this great piece of software. I hope this will help you find and fix the bug.