diff --git a/AyCode.Core/Serializers/IdentityMap.cs b/AyCode.Core/Serializers/IdentityMap.cs
index 8d251a4..68256cf 100644
--- a/AyCode.Core/Serializers/IdentityMap.cs
+++ b/AyCode.Core/Serializers/IdentityMap.cs
@@ -46,8 +46,9 @@ public interface IIdentityMap
/// The ID type (int, long, Guid, string)
public sealed class IdentityMap : IIdentityMap where TId : notnull
{
- private bool _useSmallInt = false;
+ private const bool _useSmallInt = true;
+ // Small int optimization (TId = int only, 0-4095), 512 bytes (fits in L1 cache!)
private const int SmallBitmapSize = 64;
private const int SmallSize = 4096;
@@ -55,10 +56,6 @@ public sealed class IdentityMap : IIdentityMap where TId : notnull
//private const int SmallBitmapSize = 1024;
//private const int SmallSize = SmallBitmapSize * 64;
- // Small int optimization (TId = int only, 0-4095)
- //private const int SmallSize = 4096;
- //private const int SmallBitmapSize = SmallSize / 64; // 64 ulongs = 512 bytes (fits in L1 cache!)
-
// Slot for hash table entries (generation needed for hash table validity)
private struct HashSlot
{
@@ -90,8 +87,7 @@ public sealed class IdentityMap : IIdentityMap where TId : notnull
public IdentityMap()
{
}
-
-
+
///
/// Tries to add a key to tracking (serialization).
/// Returns true if first occurrence (key was added).
@@ -311,16 +307,16 @@ public sealed class IdentityMap : IIdentityMap where TId : notnull
// NOTE: SmallInt path DISABLED for deserializer.
// The 512KB _smallValues sparse array causes cache misses.
// Hash table has better cache locality.
-
- // // Small int fast path
- // if (_useSmallInt && IsInt32)
- // {
- // var intKey = Unsafe.As(ref key);
- // if ((uint)intKey < SmallSize)
- // {
- // return TryGetOrAddSmallInt(intKey, out existing);
- // }
- // }
+
+ //// Small int fast path
+ //if (_useSmallInt && IsInt32)
+ //{
+ // var intKey = Unsafe.As(ref key);
+ // if ((uint)intKey < SmallSize)
+ // {
+ // return TryGetOrAddSmallInt(intKey, out existing);
+ // }
+ //}
// Hash table path
if (!TryAddHash(key, out var slotIndex))
@@ -335,19 +331,13 @@ public sealed class IdentityMap : IIdentityMap where TId : notnull
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool TryGetOrAddSmallInt(int key, out object? existing)
{
- // Lazy init bitmap
+ // Lazy init bitmap only - NOT _smallValues!
+ // This method is for tracking (key seen?), not value storage.
if (_smallBitmap == null)
{
_smallBitmap = ArrayPool.Shared.Rent(SmallBitmapSize);
Array.Clear(_smallBitmap, 0, SmallBitmapSize);
}
-
- // Lazy init values array (only when needed for deserialization)
- if (_smallValues == null)
- {
- _smallValues = ArrayPool