usage: the heatmap's settled-days key names the filter's zone, not its pointer (#2278)
8d4c07ffe(v0.1.2156) named the heatmap's settled days with %#v of the Filter, and the page's filter carries Zone, a *time.Location: %#v writes its address, another in each run. So heat-v1.json never matched on a start and every start paired the whole history for the heatmap again, the cost8d4c07ffewas to take away. Its bench start matched by chance. The zone is now written by its name, the rest of the filter as before. Found with a key-parts log on mote (~/r2278/full): two starts of one binary wrote headers differing only in Zone:(*time.Location)(0x1089b81e0) vs (0x105d8c1e0). After the fix three starts of a build with it: the first (new binary) and second wrote heat-v1.json, the third read it, and its heap at 18 s has no heatSplit (was 83 to 95 MB in each start before). TestHeatSettledKeyNamesTheZone: two FixedZone("Z", 3600) give one key, nil or another zone a different one. Red at 8d4c07ffe's heat_disk.go ("one zone, two keys"), green here. Run at this tree, cherry-picked ontod05482bab(mote; first run onc28cc5c87the same): go test -count=1 ./internal/usage ok (16.4s); gofmt -l clean; go vet -tags nogui ./internal/usage for linux, windows, darwin ok.
This commit is contained in:
@@ -80,9 +80,16 @@ func heatSettledKey(d heatDiskRef, cut, since time.Time, f Filter, identities ma
|
||||
if d.root == "" {
|
||||
return "", false
|
||||
}
|
||||
// the filter's zone by its name: %#v writes its pointer, another in
|
||||
// each run
|
||||
zone := ""
|
||||
if f.Zone != nil {
|
||||
zone = f.Zone.String()
|
||||
}
|
||||
f.Zone = nil
|
||||
h := sha256.New()
|
||||
fmt.Fprintf(h, "heat-v1\x00%s\x00%s\x00%s\x00%d\x00%d\x00%s\x00%#v\x00%d:%d:%d\x00",
|
||||
requestDiskBinary(), d.root, d.meta, cut.UnixNano(), since.UnixNano(), cut.Location(), f, before.n, before.at, before.tokens)
|
||||
fmt.Fprintf(h, "heat-v1\x00%s\x00%s\x00%s\x00%d\x00%d\x00%s\x00%#v\x00%s\x00%d:%d:%d\x00",
|
||||
requestDiskBinary(), d.root, d.meta, cut.UnixNano(), since.UnixNano(), cut.Location(), f, zone, before.n, before.at, before.tokens)
|
||||
hashCodexIdentities(h, identities)
|
||||
var b []byte
|
||||
rows := lentRows()
|
||||
|
||||
@@ -382,3 +382,25 @@ func TestHeatmapSettledDaysFromDisk(t *testing.T) {
|
||||
t.Fatalf("after a settled file changed %+v, cold %+v", changed, cold)
|
||||
}
|
||||
}
|
||||
|
||||
// The settled days' key names a filter's zone by its name: written with
|
||||
// %#v it named the zone's pointer, another in each run, and every start
|
||||
// paired the whole history again for the heatmap.
|
||||
func TestHeatSettledKeyNamesTheZone(t *testing.T) {
|
||||
cut := time.Date(2026, 9, 28, 0, 0, 0, 0, time.UTC)
|
||||
d := heatDiskRef{root: "r", meta: "m"}
|
||||
key := func(f Filter) string {
|
||||
k, ok := heatSettledKey(d, cut, time.Time{}, f, nil, [3][]*rowChunk{}, heatSum{})
|
||||
if !ok {
|
||||
t.Fatal("not named")
|
||||
}
|
||||
return k
|
||||
}
|
||||
a, b := key(Filter{Zone: time.FixedZone("Z", 3600)}), key(Filter{Zone: time.FixedZone("Z", 3600)})
|
||||
if a != b {
|
||||
t.Fatalf("one zone, two keys: %s, %s", a, b)
|
||||
}
|
||||
if key(Filter{}) == a || key(Filter{Zone: time.FixedZone("Y", 7200)}) == a {
|
||||
t.Fatal("another zone, the same key")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user