@@ -13,6 +13,9 @@ private const int
1313 PoolIndexBits =
1414 24 ; // Number of bits to use for pool index in handle (more bits = more pools, but less strings per pool)
1515
16+ // Maximum fill factor for deduplication table. Performance degrades when it is close to 1.
17+ private const float MaxDeduplicationTableFillFactor = 0.9f ;
18+
1619 private static readonly List < Utf8StringPool ? > Pools = new ( ) ;
1720
1821#pragma warning disable IDE1006 // Naming Styles
@@ -21,7 +24,7 @@ private const int
2124 internal static long totalAddedBytes ;
2225#pragma warning restore IDE1006 // Naming Styles
2326
24- internal int overfillCount ;
27+ internal int deduplicationFillCount ;
2528
2629 private readonly List < nint > pages = new ( ) ;
2730 private readonly int index ;
@@ -309,12 +312,9 @@ private void AddToDeduplicationTable(ulong[]? currentTable, int currentTableBits
309312 var tableEntry = currentTable [ ( tableIndex + i ) % tableSize ] ;
310313 if ( tableEntry == 0 )
311314 {
312- if ( i > 0 )
313- {
314- ++ overfillCount ;
315- }
315+ ++ deduplicationFillCount ;
316316 currentTable [ ( tableIndex + i ) % tableSize ] = handle + 1 ;
317- if ( overfillCount > tableSize / 2 )
317+ if ( deduplicationFillCount > tableSize * MaxDeduplicationTableFillFactor )
318318 {
319319 ResizeDeduplicationTable ( currentTableBits + 1 ) ;
320320 }
@@ -331,7 +331,7 @@ private void ResizeDeduplicationTable(int newBits)
331331 return ;
332332 }
333333 var newDeduplicationTable = new ulong [ 1 << newBits ] ;
334- overfillCount = 0 ;
334+ deduplicationFillCount = 0 ;
335335 var tableSize = 1 << deduplicationTableBits ;
336336 for ( var i = 0 ; i < tableSize ; ++ i )
337337 {
0 commit comments