[LIB] ModCheck: patch tests and error logging for mod loading

Started by Nightinggale, October 31, 2017, 06:57:04 PM

Previous topic - Next topic

Nightinggale

I have changed my mind regarding the release schedule and decided on a feature freeze for the next release. I have managed to get benchmarking to work and then added the ability to filter based on mod and filename. Those two are very related because the benchmarking tool uses harmony to get what it need and it provides the info for the PatchOperation anyway.

I added this:
<li Class="ModCheck.FindFile">
<modName>Core</modName>
<file>TraderKinds_Orbital_Misc.xml</file>
</li>

If one or both lines are missing, they are assumed to be correct, through I'm not sure when it will not be a good idea to fill out both.

The result from adding this meant that it went from this:
      14.7972 ms A Dog Said...
             5.6831 ms
             3.1271 ms
             2.9940 ms
             2.9930 ms

To this
       2.3822 ms A Dog Said...
             2.0231 ms
             0.1289 ms
             0.1200 ms
             0.1102 ms


After seeing how successful this is, I decided it just needs some more testing and cleaning and then it needs to be released as fast as possible because this is really something all patches should use.

I suspect the first one is slower due to some disk cache or something like that. There is no obvious reason in the file for it to be slower. There is not really anything I can do about that.
ModCheck - boost your patch loading times and include patchmods in your main mod.

larSyn

Quote from: Nightinggale on December 13, 2017, 08:50:33 AM
I have changed my mind regarding the release schedule and decided on a feature freeze for the next release. I have managed to get benchmarking to work and then added the ability to filter based on mod and filename. Those two are very related because the benchmarking tool uses harmony to get what it need and it provides the info for the PatchOperation anyway.

I added this:
<li Class="ModCheck.FindFile">
<modName>Core</modName>
<file>TraderKinds_Orbital_Misc.xml</file>
</li>

If one or both lines are missing, they are assumed to be correct, through I'm not sure when it will not be a good idea to fill out both.

The result from adding this meant that it went from this:
      14.7972 ms A Dog Said...
             5.6831 ms
             3.1271 ms
             2.9940 ms
             2.9930 ms

To this
       2.3822 ms A Dog Said...
             2.0231 ms
             0.1289 ms
             0.1200 ms
             0.1102 ms


After seeing how successful this is, I decided it just needs some more testing and cleaning and then it needs to be released as fast as possible because this is really something all patches should use.

I suspect the first one is slower due to some disk cache or something like that. There is no obvious reason in the file for it to be slower. There is not really anything I can do about that.

So, as I understand, we would be telling the ModCheck exactly where to look for the file being patched, which, by the looks of it, speeds things way up?  That's pretty awesome.  I'm going to be very curious to see what it can do for SI, as the patch files keep getting bigger.  Last time I checked it was around 1000ms to load.  Not sure if a lot of that is from the patches or just the size of the mod or both...

Nightinggale

Quote from: larSyn on December 13, 2017, 09:36:19 AMSo, as I understand, we would be telling the ModCheck exactly where to look for the file being patched, which, by the looks of it, speeds things way up?  That's pretty awesome.
That's pretty much it. It's all about how long time it will spend on a file before it figures out that it's the wrong file. xpath searches aren't quick, even if optimized. ModCheck.FindFile compares a few strings where all of them are in memory already without searching, which is more or less instant compared to xpath searching.

Quote from: larSyn on December 13, 2017, 09:36:19 AMI'm going to be very curious to see what it can do for SI, as the patch files keep getting bigger.  Last time I checked it was around 1000ms to load.  Not sure if a lot of that is from the patches or just the size of the mod or both...
The problem with the vanilla time display is that the time for each mod is for loading def files and applying patches from all mods. This mean if you say have A Dog Said..., it will apply those patches too, though the searches will be empty and not do anything to SI. To get a proper indication of time spend, you will have to disable all mods except Core and the one you want to test.

It should be noted that if you write a mod with only patch files, no defs, then it will read instantly according to vanilla because the time spend on it will be measured in the other mods. ModCheck measures time spend on each patch when patching each xml file and it adds up the numbers for each patch. This mean the numbers reported are the time spend on each patch in all mods combined.
ModCheck - boost your patch loading times and include patchmods in your main mod.

Nightinggale

ModCheck 1.6 has been released. It adds patch operation profiling and FindFile.

Quick documentation (will have to do until I rewrite everything within hopefully a few days)
<li Class="ModCheck.FindFile">
<modName>Core</modName>
<file>TraderKinds_Orbital_Misc.xml</file>
</li>

This will be true when patching the chosen file in the chosen mod. Replaces isModLoaded in most cases. FindFile and isModLoaded are equally fast once cache has been set, but setting up the cache in isModLoaded takes around the same time as FindFile use on patching 2000 def files. FindFile is uncached and has no setup overhead.

FindFile has no ability to write to the log. It's only purpose is to boost speed as much as possible. It only has those two tags as well as success tag from vanilla.

I tried benchmarking with only A Dog Said... and Dragon Mod loaded. The results are as follows:





PatchingScaling
Template
114.97 ms
114.96 ms
Optimized vanilla
25.13 ms
23.15 ms
With ModCheck.FindFile
1.51 ms
0.03 ms
Patching is the time spend when loading only the 3 mods mentioned. Scaling gives an indication to how well it will behave if mods adds another 400 def xml files, which will not be modified by the patch file. While the actual numbers highly depend on the hardware, the speed of each approach relative to each other will likely remain somewhat fixed, that is FindFile will likely be 70-80 times faster than the template on most computers.
ModCheck - boost your patch loading times and include patchmods in your main mod.

Nightinggale

I started to write documentation on how to use ModCheck. The so far only wiki page is here. Feedback is most welcome. Most importantly is it possible to understand what you are supposed to do after reading this?
ModCheck - boost your patch loading times and include patchmods in your main mod.

Nightinggale

Now that ModSync is live, I find it bad looking that ModCheck lacks an image. Because of this I want ModCheck to get a logo. However I still have no idea what it should look like. Proposals are welcome, particularly if followed up with a donated image because I can't make one myself.
ModCheck - boost your patch loading times and include patchmods in your main mod.

frenchiveruti

#51
Quote from: Nightinggale on December 16, 2017, 09:22:28 PM
I started to write documentation on how to use ModCheck. The so far only wiki page is here. Feedback is most welcome. Most importantly is it possible to understand what you are supposed to do after reading this?
Do you need any help on docs?
I have some questions regarding "isModLoaded", how can I check for multiple mods?
Lets say I make a gun mod for Vanilla, how do I check for Rimsenal and Combat Extended?

I can't make any images because I lack software :)

Nightinggale

Quote from: frenchiveruti on December 18, 2017, 07:48:04 AM
Do you need any help on docs?
Thanks, but to be completely honest I think it would be best if I write it since I know how ModCheck is supposed to be used. However feedback is most welcome because that's the only way I can tell if the text is good enough.

Quote from: frenchiveruti on December 18, 2017, 07:48:04 AMI have some questions regarding "isModLoaded", how can I check for multiple mods?
Lets say I make a gun mod for Vanilla, how do I check for Rimsenal and Combat Extended?
I wrote a wiki page for isModLoaded, though it's mostly a draft at this point (dead links etc). If you can get away with it, use FindFile and not isModLoaded (performance reasons), but sometimes you need to use isModLoaded or both.
ModCheck - boost your patch loading times and include patchmods in your main mod.

kaptain_kavern

#53
-Am I correct to assume that now, even a simple mod patching a single vanilla def, will be quicker to execute using FindFile from ModCheck rather than the "vanilla patching system"?

-For using the new version, I need both ModCheck and Harmony dll files, right?

Thank you and please keep up the good job  ;)


Once documentation will be more "stable", I could look at making French translations, but I guess they'll need proper basic modding documentation before needing to delves into patching  8)

frenchiveruti

Be sure that If I can give some feedback I will, I was asking if I could help into expanding examples of Do's and Don'ts because those are the most important in my opinion on how to use a LIB, in any real case.
For example If I want to check for multiple mods, I have to create 2 cases of "isModLoaded", instead of only one operation, with both mods named in it (similar to an AND gate, if BOTH mods AREN'T active, my mod doesn't load). or contrary, if BOTH MODS are loaded, then path, if not, give error.
In my small patch mod I ended up with this bloat:
https://github.com/frenchiveruti/PlantGrass-RW/blob/v18.00.02.00/Patches/GrassSowable.xml#L5

As you can see, I had to make 2 <li isModLoaded> in order to check for both mods, while I believe it should've been done in a single one as in either case the patching won't go ahead.

But maybe that's more complicated and not a feature right now. So relying on multiple <li> is the way to go. Am I right?
Feel free to use my code as an example for the wiki.
Greets

larSyn

Quote from: Nightinggale on December 16, 2017, 09:22:28 PM
I started to write documentation on how to use ModCheck. The so far only wiki page is here. Feedback is most welcome. Most importantly is it possible to understand what you are supposed to do after reading this?

It's pretty good.  I understood what to do with what you had written.  I hope you don't mind, but I took the liberty to rewrite some parts.  I didn't change the message, just fixed some grammar mistakes, reworded some stuff, and did some formatting.  I'll attach it this comment.  Feel free to use any of it you want, and if not, no worries.  :)

I could also take a crack at the logo.  I'll get something done in the next couple days and pm it you.  Let me know if you have any preferences (ie. color, font, etc).

[attachment deleted by admin: too old]

Nightinggale

Quote from: kaptain_kavern on December 18, 2017, 11:38:00 AM
-Am I correct to assume that now, even a simple mod patching a single vanilla def, will be quicker to execute using FindFile from ModCheck rather than the "vanilla patching system"?
Yes. ModCheck.FindFile will always be much faster than anything with xpath, even if it's just one PatchOperation with one well written xpath search.

Quote from: kaptain_kavern on December 18, 2017, 11:38:00 AM-For using the new version, I need both ModCheck and Harmony dll files, right?
Yes. If the mod already use harmony, then you don't have to replace 0Harmony.dll, though it shouldn't matter. Both versions are hopefully the same.

Quote from: kaptain_kavern on December 18, 2017, 11:38:00 AMThank you and please keep up the good job  ;)


Once documentation will be more "stable", I could look at making French translations, but I guess they'll need proper basic modding documentation before needing to delves into patching  8)
Hmm.... translating the guide. To be completely honest I didn't think of that, but it would be a good idea to translate it into all the languages that mod creators use. The documentation will however change frequently for a while, partly because I have more features planned for ModCheck.
ModCheck - boost your patch loading times and include patchmods in your main mod.

Nightinggale

Quote from: frenchiveruti on December 18, 2017, 01:47:58 PM
Be sure that If I can give some feedback I will, I was asking if I could help into expanding examples of Do's and Don'ts because those are the most important in my opinion on how to use a LIB, in any real case.
Sounds good. Remember that you can add comments in xml files by adding <!-- this is a comment -->
When adding comments to explain each step, it will work better as an example.

It looks to me like the xml parser used in RimWorld is good and that you can add comments everywhere except inside tags themselves (that would be strings, not comments). I have encountered parsers, which have restrictions on where to place comments due to less than perfect usage of the xml API.

Quote from: frenchiveruti on December 18, 2017, 01:47:58 PMFor example If I want to check for multiple mods, I have to create 2 cases of "isModLoaded", instead of only one operation, with both mods named in it (similar to an AND gate, if BOTH mods AREN'T active, my mod doesn't load). or contrary, if BOTH MODS are loaded, then path, if not, give error.
Yeah, just adding operations in a row like that will make it use the AND rules. I have been thinking of OR as well, but it looks like I need to add it in C#. I'm wondering about making something with a list of operations like PatchOperationSequence, but it supports log writing. It can then have a tag to pick what is needed for success, which can be All/Any/None of the child list operations. I do want to make such tools to make checks as versatile as possible and ideas are welcome.

Nested usage of PatchOperationSequence is supported by vanilla. This allows starting with some checks and then one or more PatchOperationSequence. If setting success to Always, it will just move on to the next one if one fails. This mean you can use FindFile to set modName, but not file and then have a PatchOperationSequence starting with FindFile where it searches for a file, but not modName. The speed different is near 0 though and it's only reasonable to use if there are more checks before the first PatchOperationSequence. Comments will be needed for readability.

Quote from: frenchiveruti on December 18, 2017, 01:47:58 PMIn my small patch mod I ended up with this bloat:
https://github.com/frenchiveruti/PlantGrass-RW/blob/v18.00.02.00/Patches/GrassSowable.xml#L5
Perhaps a bit bloated, but clearly readable. One comment though. If you put FindFile first, it will be the fastest execution (minor difference, but still not 100% the same). However error messages from isModLoaded will be written during patching. The way it is right now, the errors will be written when patching the first file, meaning it will be on the top of the log.

Also adding success to every check is good for debugging, but will bloat the log if you load 100+ mods with such comments. I plan on expanding the log writing abilities, which will allow writing only if verbose logging is enabled and I think your success messages will fall into that category.

Quote from: frenchiveruti on December 18, 2017, 01:47:58 PMAs you can see, I had to make 2 <li isModLoaded> in order to check for both mods, while I believe it should've been done in a single one as in either case the patching won't go ahead.

But maybe that's more complicated and not a feature right now. So relying on multiple <li> is the way to go. Am I right?
There is nothing, which is free. If one operation can check for multiple mods, then the C# code needs to be more complex. Now the C# code is simple, but it needs multiple calls from xml.

Quote from: frenchiveruti on December 18, 2017, 01:47:58 PMFeel free to use my code as an example for the wiki.
Thanks.
ModCheck - boost your patch loading times and include patchmods in your main mod.

Nightinggale

Quote from: larSyn on December 18, 2017, 03:48:33 PMIt's pretty good.  I understood what to do with what you had written.  I hope you don't mind, but I took the liberty to rewrite some parts.  I didn't change the message, just fixed some grammar mistakes, reworded some stuff, and did some formatting.  I'll attach it this comment.  Feel free to use any of it you want, and if not, no worries.  :)
Thanks. It's not that I suck at writing or grammar. However when writing the wiki, I has and will continue to focus on explaining how to use ModCheck correctly. This has the sideeffect of slacking off at stuff like grammar because none of us can focus 100% on everything at once. Next thing to come into play is the fact that we are all poor at correcting what we wrote ourselves. The brain can take the easy part and read half the sentence and fill out the other hard from memory because we know what it is supposed to say. This mean we can read the same sentence 5 times and still not notice the mistake we would have noticed instantly if the same had been written by somebody else.

In other words corrections like that is most welcome, be it grammar, clarifications or some other improvements. I will take a look at the document in the near future.

Just one thing. I don't actually have word on this computer and have to use wordpad. It complains that it might have removed something from the document  :-\

Quote from: larSyn on December 18, 2017, 03:48:33 PMI could also take a crack at the logo.  I'll get something done in the next couple days and pm it you.  Let me know if you have any preferences (ie. color, font, etc).
I'm thinking a logo, which while not singlecolored is primarily red. Also the other end of the color spectrum (blueish colors) should be avoided. It should be some icon, which illustrates what ModCheck is about, which is patching and speed. Since it's an icon, which should be used as preview (game, modsync, steam etc), getting the name itself through is not top priority. It's already on the screen.

I know it might be a lot to ask, but there is the idea further back in post #42 in this thread about using an svg as a logo, which mods can display if they include ModCheck. The idea is that the forum links to the git repository and then on release, the old version change color (or something) to indicate that the dll is outdated. It would be awesome if the logo can be included in something like that, like:
logo    using
logo  ModCheck
logo     1.6

I know it might be difficult to make and it's ok if it's not like that, but I really like the idea.
ModCheck - boost your patch loading times and include patchmods in your main mod.

larSyn

Quote from: Nightinggale on December 18, 2017, 07:58:43 PM
Thanks. It's not that I suck at writing or grammar. However when writing the wiki, I has and will continue to focus on explaining how to use ModCheck correctly. This has the sideeffect of slacking off at stuff like grammar because none of us can focus 100% on everything at once. Next thing to come into play is the fact that we are all poor at correcting what we wrote ourselves. The brain can take the easy part and read half the sentence and fill out the other hard from memory because we know what it is supposed to say. This mean we can read the same sentence 5 times and still not notice the mistake we would have noticed instantly if the same had been written by somebody else.

In other words corrections like that is most welcome, be it grammar, clarifications or some other improvements. I will take a look at the document in the near future.

Just one thing. I don't actually have word on this computer and have to use wordpad. It complains that it might have removed something from the document  :-\

Yeah, I understand you're trying to get the idea across first and foremost.  Like you said, we all suck at noticing our own mistakes, especially when we're trying to get something done fast.  But, that's why editors/proofreaders exist, and I don't mind helping out in that respect. 

I checked the doc with Wordpad and it didn't lose any of the changes/formatting, so you should be good too.  Just an fyi, I use Libre Writer, it's a free open source version of Word.  Might be worth checking out, if you need a word processor.

Quote from: Nightinggale on December 18, 2017, 07:58:43 PMI'm thinking a logo, which while not singlecolored is primarily red. Also the other end of the color spectrum (blueish colors) should be avoided. It should be some icon, which illustrates what ModCheck is about, which is patching and speed. Since it's an icon, which should be used as preview (game, modsync, steam etc), getting the name itself through is not top priority. It's already on the screen.

I know it might be a lot to ask, but there is the idea further back in post #42 in this thread about using an svg as a logo, which mods can display if they include ModCheck. The idea is that the forum links to the git repository and then on release, the old version change color (or something) to indicate that the dll is outdated. It would be awesome if the logo can be included in something like that, like:
logo    using
logo  ModCheck
logo     1.6

I know it might be difficult to make and it's ok if it's not like that, but I really like the idea.

Not a problem.  It's been a while since I opened up Illustrator, but it was fun to use it again.  I did a couple quick logos last night, and exported them as svg's as requested.  I'll attach them both to this comment.  To edit the xml, right click the image file and open with whatever you use for xml files (I like Sublime).  Not sure if you would need this, but this page has the code for changing the colors/fonts. And as a heads up, I found svg's don't like a lot of different fonts and won't allow things like layer effects (multiply, hard light, etc).  Let me know what you think.  I can make some edits/changes if you want.

[attachment deleted by admin: too old]