Skip to content
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

de-linq TweakScale #49

Open
pellinor0 opened this issue Oct 20, 2016 · 1 comment
Open

de-linq TweakScale #49

pellinor0 opened this issue Oct 20, 2016 · 1 comment

Comments

@pellinor0
Copy link
Owner

see http://wiki.kerbalspaceprogram.com/wiki/Garbage_Reduction

@blowfishpro
Copy link

If you do this, I think that wiki page glosses over some things that might be worth paying attention to:

  • If the alternative to Linq/foreach is creating an intermediate list/array, you're probably better off not changing anything. The array/list itself is garbage, and for larger collections the allocation size grows (whereas for Linq/foreach it should usually be constant).
    • Lists can be even worse in this regard because the backing array gets completely re-allocated each time it runs out of space (it starts at 4 by default, then when you need to add the 5th, it goes to 8, then to 16...)
  • The allocations in question are quite small, perhaps tens of bytes (don't recall exactly though). If you're not doing it very often (e.g. not every frame), then it might not be worth it.
  • The wiki article is correct that foreach will not allocate for most .net classes, but will allocate a bit for many things in KSP. Squad could fix this with a few lines of code in each affected class and I've logged an issue. My initial investigation found the problem on these classes:
    • PartResourceList
    • PartModuleList
    • AssemblyLoader.LoadedAssembyList
    • BaseFieldList
    • ConfigNode.ValueList
    • ConfigNode.ConfigNodeList
    • PartResourceDefinitionList
    • PartUpgradeHandler
    • PQSMeshPlanet.VertList
    • ShipConstruct
    • UrlDir.ConfigFileType
  • Finally, I think readability counts for something, and that for loops can often take away from readability. This is especially for loops with nested conditionals that would often replace linq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants