Closed sean- closed 5 years ago
@bluele Sorry for asking but is there a special reason for not merging this improvement?
Could you please merge it? The efficiency of Len() is very needed. It's very aggressive to preallocate all items when getting length of keys.
Please merge this!
Sorry for late response.
If you pass false to checkExpired
, you can avoid checking if each items are expired.
@sean- Thank you a lot.
Preallocate the maximum number of available items, including expired items. While this isn't optimal, it is a reasonable guess for the length.
Even though this approach results in one extra mutex acquisition, in simple
go test
benchmarking, this improves the test time from ~1.444s to ~1.332s. Presumably this improvement is the result of two things:c.mu
is locked while the GC copies data aroundThere is still room to be had by reducing the number of times
c.mu
is exclusively locked, but this is an easy performance improvement.Fixes: #43 Replaces: #50