Jira issue originally created by user pem:
The function contains uses inarray to determine if an element provided as parameter is found in the array $this->elements, and performs a strict comparison.
There might be a way to improve the performances of this function by using a foreach + if
In attachement you can find a small bench file to show the differences between in_array and foreach on object search.
You might want to run the bench with a doctrine Object to verify if this changes anything to the result.
For simple Objects, foreach is much faster when the array has less than 30k elements. Over 30k the difference flattens, and might revert around 50k (meaning that in_array might start being faster when the array has more than 50k entries).
Maybe we could provide two functions, one for smaller than 40-50k items (using foreach), and one for bigger arrays (using in_array) ?
Comment created by @guilhermeblanco:
I created more test cases and indeed foreach is around 40% faster than in_array. I applied the change in our suite, this should be available in new versions of Doctrine Common.
Issue was closed with resolution "Fixed"