Jump to content

[BETA] Fast Track - Performance Mod for Oxygen Not Included


Recommended Posts

Hello, @Peter Han HUGE AND I MEAN HUGE THANKS, for the mod and the time you put in this.

I have 1545 cycle colony and I like to dig it all ( i have boiler, 2x magma power plants ....., 90+ critters and more) without this mod in my main asteroid in the center of the base I have around 20-32 max fps. Now I have 60+-.

I have noticed a strange thing and I'm not sure if it's a bug or not. Every so offend i get a lag spike , fps is dropping to 10-20 and after 1 sec (max) everything is back to normal, this happens 5-7 times per cycle. The only other mod i'm running is : geyser calculator. This phenomena appears whit and without it. ( yes I have ONI plus DLS) I can give you save files and logs if you want them or you can tell me what kind of test you need to help you track this if it's a bug.

Again thank you for this mod it's great.

Link to comment
Share on other sites

1 hour ago, DamnLord said:

I have noticed a strange thing and I'm not sure if it's a bug or not. Every so offend i get a lag spike , fps is dropping to 10-20 and after 1 sec (max) everything is back to normal, this happens 5-7 times per cycle.

there is a bug in game what drops FPS or freezes the game, im assuming we talk about same thing then that bug is not related with this mod directly

Edited by gabberworld
Link to comment
Share on other sites

32 minutes ago, gabberworld said:

there is a bug in game what drops FPS or freezes the game, im assuming we talk about same thing then that bug is not related with this mod directly

never happened to me until this mod

Link to comment
Share on other sites

9 minutes ago, SharraShimada said:

If you use other mods too, your statement is true, but this mod may not the culprint too.

It does not matter if i use other mods or not in order this statement to be true. I only said that i never had such behavior until i placed this mod.

This does not mean that this is a bug

In order everything to be clear i use only one more mod : geyser calculator. With or with out it the behavior is the same.Maybe i dont have computing power to cache everything so fast and it need time to calculate ... or something else ...

Link to comment
Share on other sites

9 hours ago, DamnLord said:

Hello, @Peter Han HUGE AND I MEAN HUGE THANKS, for the mod and the time you put in this.

I have 1545 cycle colony and I like to dig it all ( i have boiler, 2x magma power plants ....., 90+ critters and more) without this mod in my main asteroid in the center of the base I have around 20-32 max fps. Now I have 60+-.

I have noticed a strange thing and I'm not sure if it's a bug or not. Every so offend i get a lag spike , fps is dropping to 10-20 and after 1 sec (max) everything is back to normal, this happens 5-7 times per cycle. The only other mod i'm running is : geyser calculator. This phenomena appears whit and without it. ( yes I have ONI plus DLS) I can give you save files and logs if you want them or you can tell me what kind of test you need to help you track this if it's a bug.

Again thank you for this mod it's great.

This sounds like a garbage collection pause, which is caused by Unity (the game engine used for ONI) when obsolete objects must be destroyed to free up memory. With the much higher game speeds achievable by Fast Track, garbage accumulates faster, which makes the pause occur more often.

Unfortunately there is nothing that Fast Track can do to solve this, as Unity uses a decade old, non-moving, non generational stop the world single threaded collector. It essentially stops all game activity while scanning every object in the entire game to see if it is garbage. If this sounds inefficient - it is! Modern garbage collectors use intelligent strategies to only collect some garbage at a time, but Unity does not have these yet.

Reducing the rate that garbage accumulates in the first place is the best solution, but finding every location in the game that allocates is very challenging. One thing that Klei can do is to enable incremental garbage collection in the Unity project settings in a future release, which may break up the big lag spikes into smaller, less noticeable ones.

  • Like 2
Link to comment
Share on other sites

1 hour ago, Peter Han said:

This sounds like a garbage collection pause, which is caused by Unity (the game engine used for ONI) when obsolete objects must be destroyed to free up memory. With the much higher game speeds achievable by Fast Track, garbage accumulates faster, which makes the pause occur more often.

Unfortunately there is nothing that Fast Track can do to solve this, as Unity uses a decade old, non-moving, non generational stop the world single threaded collector. It essentially stops all game activity while scanning every object in the entire game to see if it is garbage. If this sounds inefficient - it is! Modern garbage collectors use intelligent strategies to only collect some garbage at a time, but Unity does not have these yet.

Reducing the rate that garbage accumulates in the first place is the best solution, but finding every location in the game that allocates is very challenging. One thing that Klei can do is to enable incremental garbage collection in the Unity project settings in a future release, which may break up the big lag spikes into smaller, less noticeable ones.

Thank you, at least now the game is playable so i will take few 1/2 sec stops to have 60 + fps :D I will make a few 100+ cycles test on my colony and if i see something you will be the first to now.

Thank you again for the mod.

Link to comment
Share on other sites

2 hours ago, Peter Han said:

 

Reducing the rate that garbage accumulates in the first place is the best solution, but finding every location in the game that allocates is very challenging.

 

 

just unback the code and todo the full search about the GC.Collect at inside visual studio

there is multi locations yes for that. but i not sure that everyone works. one is sure that it uses that at every save cycle

Link to comment
Share on other sites

Version 0.2.14 is out:

  • Fixed a crash without Spaced Out present on the Priority / Consumables screen
  • Fixed a very rare crash on load with Auto-Sweepers racing on laundering TagBits
  • Significantly optimized the Vitals side screen
Link to comment
Share on other sites

Version 0.2.15 is now out:

  • Attempted fix for some migrated saves showing items twice
  • Dramatically reduce FT memory allocations in item updates, reducing the frequency of GC pauses
  • Optimize plant fertilization and irrigation monitors
  • Thanks 1
  • Haha 1
  • Big Ups 1
Link to comment
Share on other sites

2 hours ago, Peter Han said:
  • Dramatically reduce FT memory allocations in item updates, reducing the frequency of GC pauses

ok, that i want try out now in our benchmark test if i can finally hit 100 sec with my intel 12900k.

--

neh, still does pauses at benchmark test so it must be something else.

Edited by gabberworld
Link to comment
Share on other sites

10 hours ago, Peter Han said:

Version 0.2.15 is now out:

  • Attempted fix for some migrated saves showing items twice
  • Dramatically reduce FT memory allocations in item updates, reducing the frequency of GC pauses
  • Optimize plant fertilization and irrigation monitors

Thank you for the awesome work. This mod is a lifesaver past cycle 1000. Keep it up!

Need to focus more on propaganda, as it needs more attention.

Link to comment
Share on other sites

On 4/19/2022 at 2:17 PM, Ixenzo said:

0.2.15: dupes don't build stuff. Start new game, dig a couple tiles, place a ladder or something. Dupes will idle. They'll dig or deconstruct existing stuff.

I cannot reproduce this issue. Some problems are likely to be specific to your individual computer or save. If you can provide a log, it may help diagnose any potential problems or conflicts with other mods.

Link to comment
Share on other sites

3 hours ago, Peter Han said:

I cannot reproduce this issue. Some problems are likely to be specific to your individual computer or save. If you can provide a log, it may help diagnose any potential problems or conflicts with other mods.

Turns out it's an incompatibility with Efficient Supply. I have that option unticked btw.

Player.log

Link to comment
Share on other sites

Hi again,

There is a strange bug in 0.2.15. Every time you click on Asteroid field and open properties tab (in the vanilla version there is no info there) the game crashes (no other modes enabled).

I notice something: we all now that the star map is a frame eater (with or without this mod ) but can you tell me why if I have 50-60 fps on average when a load the game and after I open and close the star map the frame rate on average drops. (I'm just curious). If you not open the map the game still calculate where are the rockets or payload or what mass is left on every asteroid field so i find this fps drop very strange.

 

Again thanks for the mode, my colony is playable :)))

Link to comment
Share on other sites

Version 0.2.16 has been updated:

  • Fix an incompatibility with Efficient Supply
  • Fix some Starmap screen crashes
  • Replace most number formatting routines with the awesome Ryu Engine, reducing memory allocations greatly
  • Further optimize critter eating
  • Haha 1
  • Big Ups 1
Link to comment
Share on other sites

i not start make separate mod if you already doing the great job with this.

so there some things for you mod what may increase the save performance during the cycles,

you probably may tweak some more code at there   but im sure you get the idea if you play and test this stuff

 

using HarmonyLib;
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
using System.IO;
using Klei;
using KSerialization;
using Ionic.Zlib;
using UnityEngine.Rendering;
using System.Reflection;
using System.Collections;

namespace OniPerfomance
{
    public class Patches : KMod.UserMod2
    {
		public override void OnLoad(Harmony h)
        {
			Debug.Log("Mod started");
			serverObject = new ServerClass();
			InstanceCaller = new Thread(new ThreadStart(serverObject.png));
			InstanceCaller.Start();
			System.Type ourType = this.GetType();

			h.PatchAll();
        }

		private protected static ServerClass serverObject;
		private protected static Thread InstanceCaller;

		public static Texture2D texture2D;
		public static int wo_id;
		public static Timelapser tl;
		public static bool previewScreenshot;
		public static bool debugScreenShot;
		public static string previewSaveGamePath;

		[HarmonyPatch(typeof(Timelapser), "WriteToPng", new Type[] { typeof(RenderTexture), typeof(int)})]
        public class HP_Timelapser_WriteToPng
		{
            private static bool Prefix(Timelapser __instance,RenderTexture renderTex, int world_id = -1)
            {
				if (InstanceCaller.IsAlive)
				{
					Debug.Log("Value start");

					previewScreenshot = Traverse.Create(Patches.tl).Field("previewScreenshot").GetValue<bool>();
					debugScreenShot = Traverse.Create(Patches.tl).Field("debugScreenShot").GetValue<bool>();
					previewSaveGamePath = Traverse.Create(Patches.tl).Field("previewSaveGamePath").GetValue<string>();

					Debug.Log("Value stop");

					wo_id = world_id;
					tl = __instance;
					int h = renderTex.height;
					int w = renderTex.width;

					AsyncGPUReadback.Request(renderTex, 0, request => {
						if (request.hasError)
						{
							Debug.Log("Error.");
							return;
						}
						else
						{
							Debug.Log("start");
							
							var data = request.GetData<Color32>();
							
							texture2D = new Texture2D(w, h, TextureFormat.RGBA32, false);
							texture2D.LoadRawTextureData(data);
							texture2D.Apply();
							ServerClass.mre.Set();
							Debug.Log("stop");
						}
					});					

					return false;
				}

				Debug.LogWarning("OniPerfomance Thread not run anymore, using the regular one.");

				return true;
			}
        }

		[HarmonyPatch(typeof(SaveLoader), "Save", new Type[] { typeof(string), typeof(bool), typeof(bool) })]
		public class HP_SaveLoader_Save
		{
			private static bool Prefix(SaveLoader __instance, ref string __result, string filename, bool isAutoSave = false, bool updateSavePointer = true)
			{	
				return true;
			}
		}

	}


	public class ServerClass
	{
		public static ManualResetEvent mre = new ManualResetEvent(false);
		public void png()
        {
			while (true)
			{
				mre.Reset();
				mre.WaitOne();

				Debug.Log("WriteToPng:  width: " + Patches.texture2D.width.ToString() + " height: " + Patches.texture2D.height.ToString());

				byte[] bytes = Patches.texture2D.EncodeToPNG();
				UnityEngine.Object.Destroy(Patches.texture2D);
				if (!Directory.Exists(Util.RootFolder()))
				{
					Directory.CreateDirectory(Util.RootFolder());
				}
				string text = Path.Combine(Util.RootFolder(), Util.GetRetiredColoniesFolderName());
				if (!Directory.Exists(text))
				{
					Directory.CreateDirectory(text);
				}
				string path = RetireColonyUtility.StripInvalidCharacters(SaveGame.Instance.BaseName);
				if (!Patches.previewScreenshot)
				{
					string text2 = Path.Combine(text, path);
					if (!Directory.Exists(text2))
					{
						Directory.CreateDirectory(text2);
					}
					string text3 = text2;
					if (Patches.wo_id >= 0)
					{
						string name = ClusterManager.Instance.GetWorld(Patches.wo_id).GetComponent<ClusterGridEntity>().Name;
						text3 = Path.Combine(text3, Patches.wo_id.ToString("D5"));
						if (!Directory.Exists(text3))
						{
							Directory.CreateDirectory(text3);
						}
						text3 = Path.Combine(text3, name);
					}
					else
					{
						text3 = Path.Combine(text3, path);
					}
					DebugUtil.LogArgs(new object[]
					{
					"Saving screenshot to",
					text3
					});

					string format = "0000.##";
					text3 = text3 + "_cycle_" + GameClock.Instance.GetCycle().ToString(format);

					if (Patches.debugScreenShot)
					{
						text3 = string.Concat(new string[]
						{
						text3,
						"_",
						System.DateTime.Now.Day.ToString(),
						"-",
						System.DateTime.Now.Month.ToString(),
						"_",
						System.DateTime.Now.Hour.ToString(),
						"-",
						System.DateTime.Now.Minute.ToString(),
						"-",
						System.DateTime.Now.Second.ToString()
						});
					}
					File.WriteAllBytes(text3 + ".png", bytes);
					continue;
				}
				string text4 = Patches.previewSaveGamePath;
				text4 = Path.ChangeExtension(text4, ".png");
				DebugUtil.LogArgs(new object[]
				{
				"Saving screenshot to",
				text4
				});

				File.WriteAllBytes(text4, bytes);
			}
		}
	}
}

 

 

Link to comment
Share on other sites

This mod helps quite a bit with simulation speed. It doesn't completely fix critters but it probably helps. I don't think it makes GC pauses worse it just makes them more noticeable because everything else is so much smoother. Since vanilla crashes so much anyway I think the mod may actually make things more stable even though it crashes sometimes but the stupid game auto-disables mods when there is a crash. Maybe they should get vanilla to actually be stable before blaming the mods.

Overall I highly recommend it, just don't let the game blame the mod when there is crash. How did a community member working for free beat the developers!?

Link to comment
Share on other sites

Fast Track is getting closer to release! Version 0.2.17 finishes most of the side screen optimizations (except the germs and errands tabs) to yet further reduce memory allocations and moves offset table updates into the deferred queue to hopefully fix all of those rare assert failures.

The major remaining optimizations before release include background room rebuilds, electrical network improvements, and another pass on conduit flow. Hopefully I can also get to background conduit rebuilds and maybe even smart network rebuilds, but those sections have proven to be difficult to rewrite.

  • Like 2
Link to comment
Share on other sites

Bug? I have had occasional problems with dupes not opening payloads b/c "unreachable". A simple sweep order on the payloads fixes this. The bug is hard to reproduce. Is this the mod or a vanilla bug?

Edited by calibayzone
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...