Conversation
| c.ttlmu.Lock() | ||
| for k, deadBySec := range c.ttl { | ||
| if !ttlValid(deadBySec) { | ||
| delete(c.ttl, k) |
There was a problem hiding this comment.
Deleting from the map will cause increasing of internal overflow buckets inside a map, so it can produce huge gc pauses. Better to use a slice here.
There was a problem hiding this comment.
using slices tho will cause O(n) search in the locked section (in {S,G}etWithTTL methods)
| func (c *Cache) ttlGCRoutine() { | ||
| go func() { | ||
| for { | ||
| c.ttlmu.Lock() |
There was a problem hiding this comment.
it keeps map relatively small, so in practice it works pretty fast
There was a problem hiding this comment.
Is it possible to store ttl inside of buckets?
There was a problem hiding this comment.
initially I was going to do exactly that, but it caused a lot of memcopies and increased implementation complexity. current implementation is simplified, allowing to at least introduce such features and optimize further if needed.
4787439 to
3cfc486
Compare
Signed-off-by: Kirill Danshin <kirill@danshin.pro>
3cfc486 to
b5258da
Compare
|
Hmm, tests failed on travis, but works on all my environments. Checking out. |
|
Hello |
Signed-off-by: Kirill Danshin kirill@danshin.pro