The function contains uses in_array 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) ?