dkavolis / Ferram-Aerospace-Research

Aerodynamics model for Kerbal Space Program
Other
80 stars 32 forks source link

Performance optimizations #15

Closed GER-Space closed 5 years ago

GER-Space commented 5 years ago

This is a first round of small improvements to reduce memory garbage created by FAR.

  1. Most code except the voxelazation is cleaned up
  2. GUI Values are only calculated when the GUI is shown
  3. added a FARLogger.PerfStart(string). .PerfStop(string), .PerfCont(string), .PerfPause(string)

functions You create a new Stopwatch with PerfStart (id string), and you can pause or continue or just end it. When ended it will print out the time elaped.

GER-Space commented 5 years ago

this is for: #13

GER-Space commented 5 years ago

I updated the PR. Yes Its true that this only should be called once

dkavolis commented 5 years ago

https://unity3d.com/learn/tutorials/topics/performance-optimization/optimizing-garbage-collection-unity-games

According to this, value-typed variables (int, float, double and structs with only value-typed fields) should be fine to create inside functions as they are created on the stack and don't affect the GC. Also, this would make the code easier to maintain with less class members.

dkavolis commented 5 years ago

Can you submit a PR for the profile functions so the performance can be compared to the master branch?

dkavolis commented 5 years ago

Moving declarations far outside loops they are used in does not seem to do anything with performance, at least I have found nothing that would suggest otherwise. Code clarity > negligible performance improvement (if any).