You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avoid Hashtable-related allocations in AccessorTable (#6500)
Use a strongly-typed Dictionary instead.
- The key is a struct. Every time an item is added to the table or a lookup into the table is performed, the key is getting boxed. Using Dictionary avoids all this boxing.
- The struct key lacks a strongly-typed Equals. Every comparison results in a boxing. Gave the key a strongly-typed Equals.
- Every cleanup operation is allocating an enumerator. Dictionary has a struct-based enumerator.
- Every cleanup operation is allocating an array to store the items to be removed (even if there aren't any to be removed). Dictionary supports removal during enumeration, so this can be removed entirely.
Console.WriteLine("After generation {0}, removing {1} of {2} entries from AccessorTable, new count is {3}",
132
-
_generation,n,_table.Count,_table.Count-n);
131
+
Console.WriteLine($"After generation {_generation}, removed {originalCount-_table.Count} of {originalCount} entries from AccessorTable, new count is {_table.Count}");
133
132
}
134
133
#endif
135
134
136
-
// remove those entries
137
-
for(inti=0;i<n;++i)
138
-
{
139
-
_table.Remove(keysToRemove[i]);
140
-
}
141
-
142
135
++_generation;
143
136
144
137
_cleanupRequested=false;
145
138
returnnull;
146
139
}
147
140
148
141
// print data about how the cache behaved
142
+
[Conditional("DEBUG")]
149
143
internalvoidPrintStats()
150
144
{
151
145
#if DEBUG
@@ -179,7 +173,7 @@ internal bool TraceSize
179
173
180
174
privateconstintAgeLimit=10;// entries older than this get removed.
0 commit comments