Conversation
| mutation.MutatedSpecies.Organelles.Approve(true); | ||
| } | ||
|
|
||
| mutation.MutatedSpecies.Organelles.Approve(false); |
There was a problem hiding this comment.
Should this be in an else clause? Because now if the if is true above then we first all Approve and then Approve false.
src/general/HexLayout.cs
Outdated
| return existingHexes.Contains(item); | ||
| } | ||
|
|
||
| public void Approve(bool isApproved = true) |
There was a problem hiding this comment.
Why is this method named Approve? Doesn't calling Approve(false) mean that this is rejected? I think for clarity it would be nicer to have two methods: Approve and Reject without any parameters each.
src/general/HexLayout.cs
Outdated
|
|
||
| IEnumerator IEnumerable.GetEnumerator() | ||
| { | ||
| return GetEnumerator(); |
There was a problem hiding this comment.
This causes boxing due to the way the enumerator is implemented. Hopefully this is not called much?
There was a problem hiding this comment.
No, this shouldn't be called at all.
There was a problem hiding this comment.
Maybe a GD.PrintErr warning about the performance implications then? (if in the future this somehow ends up being called)
There was a problem hiding this comment.
This also happens in the current HexLayout implementation, by the way, also in the standard GetEnumerator (which is used in 66 places, Rider tells me)
There was a problem hiding this comment.
But there's a comment with a TODO about this very issue.
There was a problem hiding this comment.
I think this case is different, because this is a struct so any allocated enumerator will have a copy of the struct data and not just a reference to the data. So I kind of think that this is a slightly more problematic situation than a simple lightweight enumerator allocation. But I admit I don't fully know how structs having an enumerator function in them behave.
2bcd594 to
48f85e9
Compare
| public void WriteToArchive(ISArchiveWriter writer) | ||
| { | ||
| writer.WriteObject(existingHexes); | ||
| writer.WriteObject(existingHexes.MainHexes); |
There was a problem hiding this comment.
I'm about to start the performance / memory testing of this, so I'll just comment one more thing: I think we need a safety check here in case the data is shared as it would just cut off a portion when saving, right? So I think all of these updated save methods need a method call that the hex layout can react to and make sure it is not shared in order to save correctly. (it could also print an usage warning that only accepted species should be saved)
But silently just not writing all the data should be avoided.
hhyyrylainen
left a comment
There was a problem hiding this comment.
Trying to run a bunch of auto-evo steps I got this error:
Auto-evo failed with an exception: System.ArgumentException: Destination array was not long enough. Check the destination index, length, and the array's lower bounds. (Parameter 'destinationArray')
at System.Array.CopyImpl(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at System.Collections.Generic.Queue`1.SetCapacity(Int32 capacity)
at System.Collections.Generic.Queue`1.Enqueue(T item)
at AutoEvoRun.GatherInfo(Queue`1 steps) in /home/hhyyrylainen/Projects/Thrive/src/auto-evo/AutoEvoRun.cs:line 405
at AutoEvoRun.Step() in /home/hhyyrylainen/Projects/Thrive/src/auto-evo/AutoEvoRun.cs:line 559
at AutoEvoRun.Run() in /home/hhyyrylainen/Projects/Thrive/src/auto-evo/AutoEvoRun.cs:line 533
Note that I merged master to your branch locally before testing as I wanted to test the combined effect of this + my memory optimization. (though I guess I should merge master to this branch here on github as well to make sure we are testing the same code).
|
Here's my initial testing numbers that aren't yet super in-depth: new times (alive species):
3.072 GB memory use at the end (top of graph) old times from master branch (alive species):
5.120 GB memory use at the end (top of graph), peak likely much more More data is needed to say for sure what the effect is, but it kind of seems like that memory usage is reduced a bit (though that one massive outlier run probably affected the old memory measurement) but it also kind of seems like processing time might have increased. But we definitely need more measurements. What has your results so far looked like, just to confirm we are seeing similar things? I'm running 5 worlds to generation 15 as my usual auto-evo speed benchmark in the auto-evo exploring tool (and I'm just taking memory usages at the end for now but I think I might need to swap to running a single world to generation 15/20 and then taking the peak memory usage and fully restarting Thrive between measurements). |
7fb338e to
c0aa276
Compare
I've never gotten this error, and it seems unrelated, as I didn't make any change there. |
|
I think that error may have been a fluke / due to some unexpected merge thing. I'll resume testing this next week. |
|
Seems like the difference is now very small. I guess I have to also test the speed effect now? I'm not sure what we'll do if the effect is too small to really notice as this does make the layout handling quite a bit more complex and introduces the potential for new bugs... |
|
I'm not measuring any relevant difference now, indeed. If you don't find any difference either then idk, we can simply close this I guess. |
|
I ran a new set of measurements and it kind of maybe seems like this might have a slight advantage, though way more data would be needed: I think that before any conclusion can be reached on this, we'll need a separate PR merged into master that adds alive species at the end, total processing time, and peak memory usage stats to the worlds export (as talked about on Discord) so that it is possible to do batches like 30 worlds to generation 20 for me (these manual time checks are quite annoying for me to do and don't show a clear enough pattern with this few data points). Without that kind of large amount of data it will be quite hard to tell if this is actually speeding things up measurably. |



Brief Description of What This PR Does
Avoiding deep-cloning for the organelle layout and hex layouts in general by using temporary pooled memory for diffs only.
Progress Checklist
Note: before starting this checklist the PR should be marked as non-draft.
break existing features:
https://wiki.revolutionarygamesstudio.com/wiki/Testing_Checklist
(this is important as to not waste the time of Thrive team
members reviewing this PR)
styleguide.
Before merging all CI jobs should finish on this PR without errors, if
there are automatically detected style issues they should be fixed by
the PR author. Merging must follow our
styleguide.