Every agent request asks plugin.HasGateway (gatewayHooks, and
GatewayBegin again when on). It read plugins.json through lastgood and
steady, cloned the list, and stat'ed and read every enabled plugin's
package.json. With 12 plugins installed and none with hooks:
Windows (Ryzen AI MAX+ 395, Defender on): 457µs, 51KB, 360 allocs
macOS (M4 Pro): 251-286µs, 36KB, 260 allocs
per call. It now keeps its answer for a second, keyed on plugins.json's
path and filememo.Gen, as middleware.current does: magpie's own writes
(plugin add/remove/on/off all go through save, which calls
filememo.Forget) are seen at once, another program's within a second.
Now 0.5µs/640B on Windows and 0.3-0.85µs/208B on macOS.
Run at b9ab17231 plus this change:
- go test -count=1 -timeout 45m ./internal/plugin ./internal/middleware
./internal/gwmw ./internal/gateway: all ok (gateway 541s).
- TestHasGatewayLooksOnceASecond (new) is red with the cache turned off
by hand ("the plugins were read again within the second"), green with
it. It also checks filememo.Forget and an expired look see a change.
- The numbers come from a throwaway benchmark (12 plugin dirs with
package.json, plugins.json with options) run on this Mac and as a
windows/amd64 test binary on the Windows box, old and new code.
- GOOS=linux and GOOS=windows go vet -tags nogui on the three packages,
gofmt.
Not tried: a hooks plugin edited by hand outside magpie in the real app
(the test covers the one-second look).
Rebased onto origin/main 3fd7e1698 (no plugin or filememo change between); go build ./... and go test -count=1 ./internal/plugin ok at the pushed head. Before that, at b5d17b26e: go build ./..., linux and windows go vet -tags nogui ./internal/plugin, and go test -count=1 ./internal/plugin ./internal/middleware ./internal/gwmw all ok.