'Entity Manager remove is slow for first instance

I have list of entities which I loop over and call Entity Manager remove one after the other.

I found that the method is performing slow.

On profiling, I found that the first call to em.remove takes lot of time while the next ones happens very quickly.

I am not sure, why the first remove is slow and what can be done to improvise it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source