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 Dec 7, 2022
1 parent 565302e commit bf772ff
Show file tree
Hide file tree
Showing 7 changed files with 1,842 additions and 585 deletions.
15 changes: 4 additions & 11 deletions GameData/KSPCommunityFixes/Settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,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

// ##########################
// Modding
Expand Down
1 change: 1 addition & 0 deletions KSPCommunityFixes/KSPCommunityFixes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>portable</DebugType>
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 bf772ff

Please sign in to comment.