FractalUK / KSPInterstellar

KSP Instellar Mod for Kerbal Space Program
115 stars 67 forks source link

Fix for PluginHelper.hasTech() performance #66

Closed williamh42 closed 9 years ago

williamh42 commented 9 years ago

The hasTech() function reloads and parses the entire persistent file from disk every time - I noticed this because attaching radiators to my ships in a mid-career game was getting slow, especially if I was radially attaching multiple radiators - 8x symmetry caused nearly a full second pause.

The problem is actually worse than that, it causes a pause anytime an upgrade-able part is selected in the editor, and believe silenty causes a load delay anytime a ship is loaded (to check if parts can be upgraded) - for a ship with many radiators it could be a significant delay!

This quick hack changes it to only load acquired techs once and clears them if called in a different scene or when returning to the space center. I only briefly tested it to be sure there aren't any cases that it fails to reload the tech tree, but personally the performance is worth it even if it does.

Ideally there should (I would hope?) be a way to directly access the in-memory tree without messing with the persistant file but I only recently looked at modding (to fix this annoying bug in your otherwise awesome mod) so I don't know it either....

FractalUK commented 9 years ago

I've come up with a slightly different solution based on caching the results of the lookup in a dictionary. There are supposedly methods provided by KSP for determining the research state of technologies but unfortunately they don't reliably return the correct result.