Files
magpie/internal/appdir/dirkey_unix.go
T
yetone 390341f9ed appdir: the homes look tells folders apart by inode, not EvalSymlinks (#2278)
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.
2026-11-12 05:44:12 +08:00

33 lines
756 B
Go

//go:build unix
package appdir
import (
"path/filepath"
"golang.org/x/sys/unix"
)
// dirKey is the key two names of one folder share: its device and inode,
// which a link to it has too. sameDir's EvalSymlinks looked at every part
// of the name, and the homes look ran it for every Claude and Codex folder
// on each Sessions poll, ~3 MB of garbage per 40 polls on a real home
// (#2278). A folder that can't be looked at is keyed by its name.
type dirKey struct {
dev, ino uint64
name string
}
func keyOf(dir string) dirKey {
var st unix.Stat_t
for {
err := unix.Stat(dir, &st)
if err == nil {
return dirKey{dev: uint64(st.Dev), ino: uint64(st.Ino)}
}
if err != unix.EINTR {
return dirKey{name: filepath.Clean(dir)}
}
}
}