diff --git a/lru/lru.go b/lru/lru.go index a9f42c3f..19e2dea5 100644 --- a/lru/lru.go +++ b/lru/lru.go @@ -31,8 +31,11 @@ type Cache struct { // executed when an entry is purged from the cache. OnEvicted func(key Key, value interface{}) - ll *list.List + // cache comes first so the GC enqueues marking the map-contents first + // (which will mark the contents of the linked-list much more + // efficiently than traversing the linked-list directly) cache map[interface{}]*list.Element + ll *list.List } // A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators diff --git a/lru/typed_lru.go b/lru/typed_lru.go index 89696301..e596b1b1 100644 --- a/lru/typed_lru.go +++ b/lru/typed_lru.go @@ -29,8 +29,11 @@ type TypedCache[K comparable, V any] struct { // executed when an typedEntry is purged from the cache. OnEvicted func(key K, value V) - ll linkedList[typedEntry[K, V]] + // cache comes first so the GC enqueues marking the map-contents first + // (which will mark the contents of the linked-list much more + // efficiently than traversing the linked-list directly) cache map[K]*llElem[typedEntry[K, V]] + ll linkedList[typedEntry[K, V]] } type typedEntry[K comparable, V any] struct {