Streamline CPU remainder buffers

This commit is contained in:
Marek Lemańczyk committed 2025-10-21 20:52:09 +02:00
1 parent b418d79fb3
commit 6adf78faf6
3 files changed
+200 -75

No files matched your search

+48 -1
View File
@@ -251,7 +251,6 @@ namespace PerfectNumbers.Core
pool.Add(stack);
}
// The factor-count scratch caches were removed because divisor factorizations never repeat across scan iterations.
[ThreadStatic]
private static List<Dictionary<ulong, int>>? _ulongIntDictionaryPool;
@@ -294,6 +293,54 @@ namespace PerfectNumbers.Core
pool.Add(dictionary);
}
[ThreadStatic]
private static Dictionary<ulong, int>? _factorCountDictionary;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Dictionary<ulong, int> RentFactorCountDictionary()
{
Dictionary<ulong, int>? dictionary = _factorCountDictionary;
if (dictionary is null)
{
return new Dictionary<ulong, int>(8);
}
_factorCountDictionary = null;
dictionary.Clear();
return dictionary;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ReturnFactorCountDictionary(Dictionary<ulong, int> dictionary)
{
dictionary.Clear();
_factorCountDictionary = dictionary;
}
[ThreadStatic]
private static Dictionary<ulong, int>? _factorScratchDictionary;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Dictionary<ulong, int> RentFactorScratchDictionary()
{
Dictionary<ulong, int>? dictionary = _factorScratchDictionary;
if (dictionary is null)
{
return new Dictionary<ulong, int>(8);
}
_factorScratchDictionary = null;
dictionary.Clear();
return dictionary;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ReturnFactorScratchDictionary(Dictionary<ulong, int> dictionary)
{
dictionary.Clear();
_factorScratchDictionary = dictionary;
}
[ThreadStatic]
private static ExponentRemainderStepper _exponentRemainderStepper;