-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CollisionManager performance when new vessels are created. #174
Comments
Did a bit of additional profiling : The The The purpose of that method is to set the physics state of colliders to avoid vessel parts from colliding which each other, done by a call to So in short, the cost of the operation is exponentially worse with the loaded part count, and there isn't much that can be done to avoid it... I guess we could look at micro-optimizing the loops. Not very reliable profiling show that the native call overhead to A possible micro-optimization would be to avoid the comparison between collider.attachedRigidbody == collider2.attachedRigidbody Those are likely quite impactful and could maybe be optimized away by replacing the object comparison by caching the instanceID of the rigidbodies in Other potential optimizations could be to reimplement the data generated by Might try to take a look at this, but in the end I doubt the cost of the operation can be reduced enough to make a significant change to the "decoupling something in a high part count environment will produce a quite perceptible hitch" situation. |
From what I saw, the spikes were worse when there were multiple vessels in play. Shouldn't the colliders between vessels that are already separate already have |
I don't see any significant difference when profiling the same 450 parts as one vessel or separated as 6 vessels. |
Well, for BDArmory combats, there are frequently 6 or more vessels in loading range (often more for those that like to do fleet combat) (the Physics Range Extender mod is used to increase the physics range), so for our usage, it would likely be quite a significant improvement. Thanks for looking into this, btw! |
Anything is possible, but I would rather try to optimize the general case first before attempting complicated corner-case optimizations requiring behavior changes that are always prone to introducing insidious bugs and side effects. |
Okay, dafter fiddling a bit, for my 450 parts test vessel I'm around 12ms vs 43ms for the stock method when benchmarking manually in a non-debug install. Need to do a few more tests to ensure there is no behavior change, but this sounds good enough to me. On a side note, the stock method behavior is quite erratic in regard to how the "enable same vessel interactions" PAW option is treated when physicless parts are involved. Not really worth a fix IMO, especially since that would add back quite bit of overhead... |
…3-4 times faster update of parts inter-collision state, significantly reduce stutter on docking, undocking, decoupling and joint failure events.
That's great and very much appreciated! |
Some profiling results (non-debug install, average over 100 calls) :
So KSPCF is between 3 and 4 times faster than stock. Doing some frame time profiling, when accounting for the 3-4 frames where some extra processing is done as a result of the decoupling action, when comparing the cost of the CollisionManager update vs the overall overhead on top of the baseline frame time, it is less than 5% for the 500 parts case, but still around 30-40% for the 1000 parts case, and this of course will scale exponentially worse with higher part counts. I gave a more in depth look at the possibility of doing less work in the multiple vessels case, but this is very difficult as KSP is triggering the update from dozens of code paths. This would require a lot of careful stock code path analysis to make it work, and would break anyway if a plugin uses the mess of related public APIs. There are at least 5 public direct ways this can be triggered : |
Patch pushed in release 1.33.0 |
As part of the on-going development of BDArmory, I was profiling KSP while launching a series of 12 missiles from standard BDA+ missile rails on a vessel. As can be seen from this image,
![image](https://private-user-images.githubusercontent.com/18440126/293603085-f06c8524-c1a1-4928-a512-0183c75a5643.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA5ODgwMjMsIm5iZiI6MTcyMDk4NzcyMywicGF0aCI6Ii8xODQ0MDEyNi8yOTM2MDMwODUtZjA2Yzg1MjQtYzFhMS00OTI4LWE1MTItMDE4M2M3NWE1NjQzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE0VDIwMDg0M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdhNWRiMjg3OTZjYTVlZWQxM2IyMmRkY2IxMWEwNTk0Y2JkMDYzZDJmNzcxOGFhZTg0ODI5ZWZlYzM0MmNlYWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.niApFMcK34cSSE_7VxPXlDb8Y9QGf_zLUyBW4tvXmSs)
each launch causes a large spike in the frame duration due to the
CollisionManager
and involves a large amount of small GC allocations. The size of these spikes gets significantly worse the more vessels (with part counts on the order of 50—100 parts) that are in play (in the above image there were 6 vessels, but only one was firing). During combat with vessels of >100 parts, I've seen instances where theCollisionManager
takes over 1000ms (of a 1200ms frame) whenever missiles are launched / new vessels are created (it doesn't need to be missiles, the same spikes are seen when just decoupling parts).Is this something that the KSPCommunityFixes team could take a look at and maybe improve?
The text was updated successfully, but these errors were encountered: