Every request served by the GUI and the gateway goes through AllowGuard,
and AllowGuard read the allow list through settings.LoadChecked. That
call reflect-copies the whole Settings each time. /api/state did the same
through Load, then only encoded the result.
Changes:
- New settings.SharedChecked(). It is Shared plus LoadChecked's error.
While settings.json parses whole it returns the settings parse already
keeps, with no copy. Otherwise, or while a write is in progress, it
falls back to loadChecked, so an unreadable file is still unknown,
never an empty list.
- allowList reads AllowIPs through SharedChecked.
- state() reads settings through Shared. Nothing in gui writes into
stateJSON.Settings (grepped for field, map and append writes).
Measured on mote with the real-account sandbox, allocations under
Settings.clone/deepCopy over 40 /api/state polls:
- before: 1.5 MB and 1 MB
- after: 0 and 0
The totals vary run to run (t32 34.6-35.1 MB, t33 24.8-30.8 MB).
Run on mote:
- go vet on settings, gateway and gui.
- go test, all of internal/settings.
- go test, internal/gateway -run "Allow|Remote|LAN|Lan|Origin|Guard".
- go test, internal/gui -run "State|Settings|Allow".
All ok.
New test: TestSharedCheckedReadsOnceAndKnowsUnknown checks that a change
is read and that a file that doesn't parse is an error. With the shared
path broken by hand (made to fall through to loadChecked), it goes red:
24 allocations against LoadChecked's 24.
Not tried: the full gateway and gui suites.