The API in Fusion runs in the main thread so any attempts to run code in a separate thread won't end up helping. The C++ API is what's implemented internally. Using C++ calls the API directly and using any other language goes through a wrapper but also ends up calling the same internal C++ functions. There is some overhead because of going through the wrapper but in most cases, it's probably not enough to matter. Let's say there's an overhead of .005 seconds per API call. (I haven't timed this but my guess is that this probably isn't too far off.) If you have a program that's making thousands of calls through the API, then it could start to make a difference but otherwise, it's probably not enough to worry about.
The other area that will contribute to the performance difference between Python and C++ is what you're doing exclusively within your program. If you have a lot of data that you're crunching a C++ program is probably going to be faster. In your example, I would guess you won't see much difference if you re-wrote your program in C++. It would be an interesting test though.
I think mostly what you're seeing is the performance of Fusion itself. Whether you make a call from C++ or Python, the actual handling of that function call by Fusion is going to take the same amount of time. If it takes 0.3 seconds to copy and paste a component in the UI you don't really notice it but if you're doing that multiple times in the API, now it definitely becomes noticeable. There's nothing you can do to speed up this other than possibly report significant issues and hope the development team can improve the performance.
I'm not sure where most of the time is being taken in your program between placing the new occurrence and adding joints. The joint system is continually resolving when you add new joints. One thing you could try, if that is what's taking a lot of time, is to play with moving the timeline marker so that most of the joints are beyond the timeline marker and won't be solved. For example, you can create the occurrence and the needed joints, then move the timeline marker to before the joints and then place the next occurrence and joints and then move the marker to before these joints and continue this process. At the end then move the timeline marker to the end. I'm not sure if it will make much of a difference or not, but it wouldn't be too hard to try.
---------------------------------------------------------------
Brian EkinsInventor and Fusion 360 API Expert
Website/Blog:
https://EkinsSolutions.com