gui: the heap grows by a quarter between reads, 16 MB at least
steadyGCStart let a window's heap grow by half of what it holds (32 MB at least) between collections. On a real account's history, ~100 MB live, that rested at a 171 MB footprint with a 200 MB peak. A quarter (16 MB at least) costs the polls nothing measurable and gives the memory back. Measured on mote (macOS 27, M5 Pro) with the owner's real account copy, network blocked, the v0.1.3435 tree: - idle 115s: footprint 171 -> 146 MB, peak 200 -> 166 MB, CPU 0.33s both - 60 busy rounds of state/providers/drift/sessions/overview: CPU 5.12s -> 5.14s, footprint 157 -> 151 MB, peak 177 -> 169 MB Run: go test -run 'Steady|GC|Tight' ./internal/gui on mote, ok; gofmt clean. TestSteadyPercent's cases follow the new numbers.
This commit is contained in:
@@ -969,13 +969,16 @@ func retightenGC() {
|
||||
afterNextGC(retightenGC)
|
||||
}
|
||||
|
||||
// steadyGCStart has the heap grow by half of what it holds before a
|
||||
// steadyGCStart has the heap grow by a quarter of what it holds before a
|
||||
// collection, or by steadyGCRoom when that is more, not Go's default of
|
||||
// all of it, for the life of the process; a GOGC the user set is kept.
|
||||
// A window resting on ~60 MB live polls /api/state, /api/drift and
|
||||
// /api/providers, ~10 MB thrown away a round, so at the default its
|
||||
// footprint peaked at 138 MB; under half, 107-108 MB, for ~9% more CPU in
|
||||
// the polls. Reads under a tight GC still set their tenth while they run.
|
||||
// footprint peaked at 138 MB and under half at 107-108 MB. On a real
|
||||
// account's history (~100 MB live) a quarter took the resting footprint
|
||||
// from 171 to 146 MB and its peak from 200 to 166 MB, with 60 busy poll
|
||||
// rounds at 5.14s of CPU against 5.12s. Reads under a tight GC still set
|
||||
// their tenth while they run.
|
||||
func steadyGCStart() {
|
||||
if os.Getenv("GOGC") != "" {
|
||||
return
|
||||
@@ -992,13 +995,13 @@ func steadyGCStart() {
|
||||
}
|
||||
}
|
||||
|
||||
// steadyGCPercent is the half steadyGCStart lets the heap grow by.
|
||||
const steadyGCPercent = 50
|
||||
// steadyGCPercent is the quarter steadyGCStart lets the heap grow by.
|
||||
const steadyGCPercent = 25
|
||||
|
||||
// steadyGCRoom is the least it grows by: half of a small heap is a few
|
||||
// MB, and a heap under 64 MB grows by 32 MB, never by more than Go's
|
||||
// steadyGCRoom is the least it grows by: a quarter of a small heap is a
|
||||
// few MB, and a heap under 64 MB grows by 16 MB, never by more than Go's
|
||||
// default.
|
||||
const steadyGCRoom = 32 << 20
|
||||
const steadyGCRoom = 16 << 20
|
||||
|
||||
// steadyPercent is the GOGC steadyGCStart sets on a live heap of live
|
||||
// bytes (0 before the first collection: steadyGCPercent).
|
||||
|
||||
@@ -144,19 +144,20 @@ func TestTightGCRetunesAfterACollection(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSteadyPercent: between reads the heap grows by half of what it
|
||||
// holds, by 32 MB when that is more, and never by more than Go's default.
|
||||
// TestSteadyPercent: between reads the heap grows by a quarter of what it
|
||||
// holds, by 16 MB when that is more, and never by more than Go's default.
|
||||
func TestSteadyPercent(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
live int64
|
||||
want int
|
||||
}{
|
||||
{0, 50},
|
||||
{60 << 20, 53},
|
||||
{64 << 20, 50},
|
||||
{0, 25},
|
||||
{60 << 20, 26},
|
||||
{64 << 20, 25},
|
||||
{8 << 20, 100},
|
||||
{16 << 20, 100},
|
||||
{32 << 20, 100},
|
||||
{500 << 20, 50},
|
||||
{32 << 20, 50},
|
||||
{500 << 20, 25},
|
||||
} {
|
||||
if got := steadyPercent(c.live); got != c.want {
|
||||
t.Errorf("steadyPercent(%d MB) = %d, want %d", c.live>>20, got, c.want)
|
||||
|
||||
Reference in New Issue
Block a user