Skip to content

Commit

Permalink
More ConfigNode perf (#90)
Browse files Browse the repository at this point in the history
* Rewrite more of ConfigNode. Avoid all recursion when reading from disk. Add further optimization around specific use cases (craft, sfs, cache loading). Add blacklist support (assumes all values are sane unless otherwise informed).

* Try with MemoryMappedFile

* Read to a char array, more inlining and optimizing

This is better than it was, but in some cases the old version outperforms it.

Fix some further parser issues, switch to new method of reading files

Remove unused code from parser

* Remove confignodeperf settings blocks, upodate readme

* ConfigNodePerf: Patch copy, tostring, and parse as well. Refactor parse method so it can be used for either file or string case.

* Allow not writing indents when saving nodes.

* Found another copypasta issue with Santiize...

* Rewrite ReadObject/WriteObject and associated code. Works fine in test but crashes my live game...

* Add KSPAssembly attribute

* Fixed exception when single field is specified more than once due to cfg error

* Fix not saving nodes for objects/components when writing, cache fieldless objects to prevent recreating them when Persistent is applied wrongly

* Fix fallback decoding for ReadFile

* Don't double translate on load fail. Use a static stringbuilder, and reflect to clear previous chunks.

* Further expand on notes in readme, clean up last bits prior to merge. Force sanitize off in the UpgradePipeline patch.
  • Loading branch information
NathanKell authored and gotmachine committed Jan 30, 2023
1 parent 4228cf5 commit 436d3e3
Show file tree
Hide file tree
Showing 7 changed files with 1,841 additions and 587 deletions.
15 changes: 4 additions & 11 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,10 @@ KSP_COMMUNITY_FIXES
// and every time you delete a vessel in the Tracking Station
FewerSaves = false

// These settings will make ConfigNode's loader not bother doing
// Extended checking during parsing for keys named ths
CONFIGNODE_PERF_SKIP_PROCESSING_KEYS
{
item = serialized_plugin
}
// or for keys that start with this.
CONFIGNODE_PERF_SKIP_PROCESSING_SUBSTRINGS
{
item = **skipProc**
}
// This tweak will skip writing indents when saving craft files and
// savegames (sfs files). This will speed up writing (and slightly
// speed up reading) at the cost of human readability.
SkipIndentsOnSavesAndCraftFiles = false

// The stock ModuleAsteroidDrill and ModuleCometDrill do a lot of unnecessary iterating over all
// PartModules on the vessel to see if an asteroid or comet is attached.
Expand Down
2 changes: 0 additions & 2 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
<DefineConstants>DEBUG;TRACE;ENABLE_PROFILER</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<DebugType>portable</DebugType>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
Expand Down
5 changes: 4 additions & 1 deletion KSPCommunityFixes/Modding/ModUpgradePipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,13 @@ private static Version GetVersion(Assembly asm)

private static void AddVersions(ConfigNode node, LoadContext loadContext)
{
if(loadContext == LoadContext.SFS)
var oldDoClean = Performance.ConfigNodePerf._doClean;
Performance.ConfigNodePerf._doClean = false;
if (loadContext == LoadContext.SFS)
node.GetNode("GAME").SetValue("_modVersions", _versionString, true);
else
node.SetValue("_modVersions", _versionString, true);
Performance.ConfigNodePerf._doClean = oldDoClean;
}

private static void ShipConstruct_SaveShip_Postfix(ref ConfigNode __result)
Expand Down
Loading

0 comments on commit 436d3e3

Please sign in to comment.