FirstPersonKSP / RasterPropMonitor

Plugin for Kerbal Space Program
https://forum.kerbalspaceprogram.com/index.php?/topic/190737-18x-rasterpropmonitor-adopted/&tab=comments#comment-3723047
Other
24 stars 13 forks source link

altitudeBottom caching #113

Closed farhannysf closed 9 months ago

farhannysf commented 9 months ago

This PR is more of a draft for altitudeBottom caching implementation. I haven't test this yet, but could work theoretically.

In this version of the code, caching is implemented to store already calculated altitudes. This implementation will make the code faster if the number of parts does not change often, but slower if the number of parts changes frequently (because the cache has to be updated). Also, it will use more memory to store the cache.

Additionally, the vessel.parts call is stored in a variable before the loop to avoid excessive calls, although this is a minor optimization and may not result in a noticeable performance improvement. .

Please note that the cache needs to be updated or cleared when certain changes occur in the game such as parts being added/removed from the vessel. Using caching comes with trade-offs. It increases memory usage and could lead to stale data if not properly managed. Additionally, if the number of parts changes frequently, the overhead of updating the cache could negate the performance gains.