ClaudeHomesIn and CodexHomesIn run on every Sessions poll, and keyed each folder they found by filepath.EvalSymlinks, which Lstats every part of the name: ~3 MB of garbage per 40 polls on a real home. On unix a folder is now keyed by its device and inode, which a link to it shares; a folder that can't be looked at is keyed by its name, and other systems keep EvalSymlinks. The folder checks use DirStat, moved here from internal/sessions so both share one. Run (mica, at this tree): go vet for darwin and windows of appdir, sessions, provider and gui, for linux of the first three (gui needs cgo there); GOOS=freebsd go build; go test ./internal/appdir ./internal/sessions ./internal/provider ok. TestHomesLookAllocatesLittle: 55 and 68 allocations a look now, 387 and 400 on the old code, which fails it. Real account (mote, 40 polls of /api/sessions): w9 31.28 MB allocated with os.lstatNolog 3 MB; w10 25.98 MB, lstat gone from the top list. CPU over 30s 1.47s, within noise of w8's 1.29s at mote's load.
19 lines
443 B
Go
19 lines
443 B
Go
//go:build !unix
|
|
|
|
package appdir
|
|
|
|
import "path/filepath"
|
|
|
|
// dirKey is the key two names of one folder share: where its links lead.
|
|
type dirKey struct{ name string }
|
|
|
|
func keyOf(dir string) dirKey { return dirKey{name: sameDir(dir)} }
|
|
|
|
// sameDir is the key two names of one folder share: where its links lead.
|
|
func sameDir(dir string) string {
|
|
if r, err := filepath.EvalSymlinks(dir); err == nil {
|
|
dir = r
|
|
}
|
|
return filepath.Clean(dir)
|
|
}
|