Menu

#Getoradd

2 posts

Feed·
2 of 2 posts
GetOrAdd Ran My Factory Three Times
📰
0Read More

GetOrAdd Ran My Factory Three Times

DEV Community: dotnet·Sukhpinder Singh·about 7 hours ago
#uj59hZG9
#devtodotnet#devto#dev#factory#callers

ConcurrentDictionary.GetOrAdd can run your value factory more than once when threads race on the same key. Only one result is kept, but the extra factories still execute. Here's the race and the one-line Lazy fix.

15s
440 MB of Closures on Pure Cache Hits
🖼️
0Read More

440 MB of Closures on Pure Cache Hits

DEV Community: dotnet·Sukhpinder Singh·1 day ago
#OVZ73Iho
#devtodotnet#devto#dev#getoradd#salt

My ConcurrentDictionary cache was all hits, yet it churned the GC. The GetOrAdd factory closed over a loop-local, so it allocated a closure on every call even though the factory never ran. The state-arg overload does the same work at zero bytes.

15s