From c787beb65539c9aa11c9734a8a21bbd0575a07ac Mon Sep 17 00:00:00 2001 From: JustArchi Date: Mon, 26 Jun 2017 05:02:40 +0200 Subject: [PATCH] Add hacked optimization mode --- ArchiSteamFarm.sln.DotSettings | 1 + ArchiSteamFarm/GlobalConfig.cs | 3 +- ArchiSteamFarm/Hacks.cs | 56 ++++++++++++++++++++++++++++++++++ ArchiSteamFarm/Program.cs | 4 +++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 ArchiSteamFarm/Hacks.cs diff --git a/ArchiSteamFarm.sln.DotSettings b/ArchiSteamFarm.sln.DotSettings index b7229d668..4d38dca98 100644 --- a/ArchiSteamFarm.sln.DotSettings +++ b/ArchiSteamFarm.sln.DotSettings @@ -354,6 +354,7 @@ EWCF FA FS + GC HTML ID IP diff --git a/ArchiSteamFarm/GlobalConfig.cs b/ArchiSteamFarm/GlobalConfig.cs index cff53bdcb..2dfd0f171 100644 --- a/ArchiSteamFarm/GlobalConfig.cs +++ b/ArchiSteamFarm/GlobalConfig.cs @@ -182,7 +182,8 @@ namespace ArchiSteamFarm { internal enum EOptimizationMode : byte { MaxPerformance, - MinMemoryUsage + MinMemoryUsage, + MaxPerformanceWithPeriodicalGC = 255 // Hack, don't depend on this } [SuppressMessage("ReSharper", "UnusedMember.Global")] diff --git a/ArchiSteamFarm/Hacks.cs b/ArchiSteamFarm/Hacks.cs new file mode 100644 index 000000000..0980cba13 --- /dev/null +++ b/ArchiSteamFarm/Hacks.cs @@ -0,0 +1,56 @@ +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015-2017 Łukasz "JustArchi" Domeradzki + Contact: JustArchi@JustArchi.net + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +using System; +using System.Runtime; +using System.Threading; + +namespace ArchiSteamFarm { + internal static class Hacks { + private const byte GarbageCollectorDelay = 1; + + private static Timer GarbageCollectionTimer; + private static Timer GarbageCompactionTimer; + + internal static void Init() { + if (GarbageCollectionTimer == null) { + GarbageCollectionTimer = new Timer( + e => GC.Collect(), + null, + TimeSpan.FromSeconds(GarbageCollectorDelay), // Delay + TimeSpan.FromSeconds(GarbageCollectorDelay) // Period + ); + } + + if (GarbageCompactionTimer == null) { + GarbageCompactionTimer = new Timer( + e => GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce, + null, + TimeSpan.FromMinutes(GarbageCollectorDelay), // Delay + TimeSpan.FromMinutes(GarbageCollectorDelay) // Period + ); + } + } + } +} \ No newline at end of file diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index b211a5ca4..969200d6d 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -232,6 +232,10 @@ namespace ArchiSteamFarm { return; } + if (GlobalConfig.OptimizationMode == GlobalConfig.EOptimizationMode.MaxPerformanceWithPeriodicalGC) { + Hacks.Init(); + } + if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture)) { try { // GetCultureInfo() would be better but we can't use it for specifying neutral cultures such as "en"