-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FlightIntegrator and friends micro-optimization (#230)
* Library methods reorganization * A bunch of FlightIntegrator and VesselPrecalculate optimizations, mainly relevant in large part count situations. More can be done : I didn't touch yet stuff specific to aero situations (drag, conduction occlusion...) and there is probably something to be done about Integrate() * Many experimental perf improvements, basically a big collection of micro-optimizations for various pieces of code running every frame on every part. Won't do much in low part count situations, and some patches are highly situational (atmospheric flight, docking ports, struts, particles repositionning on floating origin shifts...) Patches affecting the FlightIntegrator and VesselPrecalculate are broably incompatible with mods trying to override/extend stuff through MFI. There are a bunch of perf issues with "end of the call stack" methods being inefficient because they do extra work that is already done at the call site or can be made faster by using state from the call site, so patching those methods doesn't cut it, but this mean many stock methods aren't called anymore, so if those methods are replaced/prefixed/postfixed with MFI, things will break. Notable examples are FI.UpdateAerodynamics() and FI.Integrate(Part). This could probably be avoided at the cost of some of the perf gains, but I wanted to see how far things could be pushed perf wise. On a side note, there is a bug lurking in the VesselPrecalculate.CalculatePhysicsStats reimplementation, not sure what it is exactely but a side effect is camera target being wrongly offset. Likely something with the CoM calcs. * Fix incorrect vessel localCom when root part is not the control point -most notably this caused the camera to be anchored to the wrong place --------- Co-authored-by: JonnyOThan <jonnyothan@gmail.com>
- Loading branch information
1 parent
441f2d7
commit 7346056
Showing
8 changed files
with
2,711 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace KSPCommunityFixes.Library.Collections | ||
{ | ||
internal class FastStack<T> where T : class | ||
{ | ||
private T[] _array = Array.Empty<T>(); | ||
private int _size; | ||
|
||
public void EnsureCapacity(int capacity) | ||
{ | ||
if (_array.Length < capacity) | ||
_array = new T[capacity]; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public void Push(T item) | ||
{ | ||
_array[_size++] = item; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public bool TryPop(out T result) | ||
{ | ||
if (_size == 0) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
result = _array[--_size]; | ||
_array[_size] = null; | ||
return true; | ||
} | ||
|
||
public void Clear() | ||
{ | ||
Array.Clear(_array, 0, _size); | ||
_size = 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.