Optimization slows down over time


My optimization becomes slower over time.

While the first 20 results arrive quickly, after 200 or so the optimization holds and it takes hours to complete even one run.

The memory remains more or less constant. The CPU load goes to 100% and remains there.

I did a basic profilter check and it shows me that the hardest method is PositionSelectByTicket. Can this be a reason?

Otherwise, who can suggest methods how to find the problem?

Can it be a memory leak? How to find it?

How can I use the profiler to find growing "complexity" of my code during the backtest runs during the optimization?