mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-05-31 22:58:32 +00:00
update memory pool cleaning frequency
This commit is contained in:
parent
eda05e5af3
commit
3383f01107
|
@ -24,6 +24,11 @@ import (
|
|||
"codeberg.org/gruf/go-list"
|
||||
)
|
||||
|
||||
// frequency of GC cycles
|
||||
// per no. unlocks. i.e.
|
||||
// every 'gcfreq' unlocks.
|
||||
const gcfreq = 1024
|
||||
|
||||
// SimpleQueue provides a simple concurrency safe
|
||||
// queue using generics and a memory pool of list
|
||||
// elements to reduce overall memory usage.
|
||||
|
@ -32,7 +37,7 @@ type SimpleQueue[T any] struct {
|
|||
p elemPool[T]
|
||||
w chan struct{}
|
||||
m sync.Mutex
|
||||
n uint8
|
||||
n uint32 // pop counter (safely wraps around)
|
||||
}
|
||||
|
||||
// Push will push given value to the queue.
|
||||
|
@ -72,14 +77,13 @@ func (q *SimpleQueue[T]) Pop() (value T, ok bool) {
|
|||
q.l.Remove(tail)
|
||||
q.p.free(tail)
|
||||
|
||||
if q.l.Len() == 0 {
|
||||
// Every 255x we reach a zero
|
||||
// length queue, sweep mem pool.
|
||||
if q.n++; q.n == ^uint8(0) {
|
||||
// Every 'gcfreq' pops perform
|
||||
// a garbage collection to keep
|
||||
// us squeaky clean :]
|
||||
if q.n++; q.n%gcfreq == 0 {
|
||||
q.p.GC()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
q.m.Unlock()
|
||||
return
|
||||
|
@ -132,13 +136,12 @@ func (q *SimpleQueue[T]) PopCtx(ctx context.Context) (value T, ok bool) {
|
|||
q.l.Remove(elem)
|
||||
q.p.free(elem)
|
||||
|
||||
if q.l.Len() == 0 {
|
||||
// Every 255x we reach a zero
|
||||
// length queue, sweep mem pool.
|
||||
if q.n++; q.n == ^uint8(0) {
|
||||
// Every 'gcfreq' pops perform
|
||||
// a garbage collection to keep
|
||||
// us squeaky clean :]
|
||||
if q.n++; q.n%gcfreq == 0 {
|
||||
q.p.GC()
|
||||
}
|
||||
}
|
||||
|
||||
// Done with lock.
|
||||
q.m.Unlock()
|
||||
|
|
Loading…
Reference in a new issue