For a long time now, I've been coding an application in Visual Basic that connects to Solidworks, and makes various measurements or manipulations of Temporary (Virtual) Bodies. I have noticed, many times now, that Solidworks API calls sometimes happen very quickly, and sometimes they are slow, even if I'm repeating the exact same operation. Trying to track down the cause, I made absolutely sure that my application repeats the same operations identically (no broken references, no memory leaks or leftover Temporary Bodies, etc.), yet somehow, seemingly randomly, the operation that takes, say, 6 seconds normally, sometimes takes 23.
I have tried to catch the culprit many times, adding breakpoints to see which operations take the most time, and several times I did manage to narrow down that slow performance to exact API calls (such as Operations2, Display3, CreateBodyFromBox, etc.). Thing is, sometimes they run fast, and sometimes they run slow, even if I'm running the code in identical manner (starting Solidworks, starting my IDE, running the code with API calls, noting the time elapsed, closing down everything, and then repeating all these steps again to make sure there are no memory leaks/leftover bodies, etc.)
It's almost as if Solidworks has it's "good days" and "bad days". I have spent dozens of hours trying to figure this out (most of it making absolutely sure that it's not my code that's causing this), and I still have no clue. Have any of you ever noticed anything similar? Is this something that happens only during external interfacing with Solidworks (as opposed to macros or plug-ins)?
P.S. I am running Solidworks 2018 x64 SP3 on a powerful PC with no other applications running. I tested the antivirus (by disabling it), but it doesn't seem to affect this. I can provide more info if needed, but I am not sure where to look for the cause.