Skip to content

Commit a8c4d7e

Browse files
committed
test(bench): AX-11 harnesses for data/options/contract/embed/entitlement/i18n/lock/sql/utils/info/config
Wave D — the last 11 benchable primitives. This closes the AX-11 sweep on core/go: every benchable file now has a perf contract gate alongside its tests and examples. * data.go — Data.New + ReadFile/ReadString hit/miss + List + ListNames + Mounts (over fstest.MapFS fixture) * options.go — NewOptions empty/2/5 + Set insert/update + Get hit/miss + Has + typed String/Int/Bool/Float64/Duration accessors + Duration string-parse + Len + Items + Result.New * contract.go — New + WithOption/WithOptions/WithServiceLock CoreOptions + ActionServiceStartup/Shutdown + ActionTaskStarted/ Progress/Completed contract structs * embed.go — Mount root/sub + Embed.ReadFile/ReadString/Open/ReadDir + Sub/FS/BaseDirectory + AddAsset/GetAsset/GetAssetBytes * entitlement.go — Entitled default/quantity/custom + denied (Security log silenced via quietDefault) + NearLimit below/above/ unlimited + UsagePercent + SetEntitlementChecker + SetUsageRecorder + RecordUsage nil/with-recorder * i18n.go — Translate default/with-translator/with-args + Language + SetLanguage no-translator/with-translator + AvailableLanguages + AddLocales + Locales + SetTranslator + Translator hit * lock.go — c.Lock lookup (warm) + LookupOrCreate (cold) + Lock/Unlock + RLock/RUnlock + TryLock + LockEnable + LockApply + Startables/Stoppables 0/5 registered * sql.go — SQLOpen no-driver + SQLDrivers + SQLIsNoRows hit/miss/ wrapped (no driver imported in core/go itself; type aliases dominate the file) * utils.go — ID + ValidateName hit/empty/traversal + SanitisePath safe/traversal + JoinPath + IsFlag + Arg/ArgString/ ArgInt/ArgBool + FilterArgs + ParseFlag (all four shapes) * info.go — Env CoreKey/OSKey/Fallthrough/Missing + EnvKeys + OS/Arch/GoVersion/NumCPU + StackBuf * config.go — New + Set fresh/update + Get hit/miss + String/Int/Bool hit + ConfigGet[float64] + Enable/Disable/Enabled + EnabledFeatures + NewConfigVar + ConfigVar Get/Set/ IsSet/Unset Bench coverage now spans 60 source files in core/go — every benchable primitive. Unbenchable files (assert/cli_assert/test/exit/signal/os/ process/command/cli/lsp) are excluded by category, not by oversight.
1 parent 6b76ddb commit a8c4d7e

11 files changed

Lines changed: 1590 additions & 0 deletions

config_bench_test.go

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
// SPDX-License-Identifier: EUPL-1.2
2+
3+
// Benchmarks for the Config primitives in config.go.
4+
// Per AX-11 — c.Config() backs every settings read across the
5+
// framework: host names, ports, paths, feature gates. String/Int/Bool
6+
// fire per-call from CLI command handlers, Service.OnStart wiring,
7+
// and Wails-RPC bindings. Feature flag Enabled() runs on every gated
8+
// code path. ConfigVar[T] is the per-package field used by services
9+
// to declare typed config slots.
10+
//
11+
// Run: go test -bench='BenchmarkConfig' -benchmem -run='^$' .
12+
13+
package core_test
14+
15+
import (
16+
. "dappco.re/go"
17+
)
18+
19+
// Sinks defeat compiler DCE.
20+
var (
21+
configSinkConfig *Config
22+
configSinkString string
23+
configSinkInt int
24+
configSinkBool bool
25+
configSinkResult Result
26+
configSinkStrings []string
27+
)
28+
29+
// configFixture returns a Config pre-populated with typical settings.
30+
func configFixture() *Config {
31+
c := (&Config{}).New()
32+
c.Set("database.host", "homelab.lthn.sh")
33+
c.Set("database.port", 5432)
34+
c.Set("api.timeout", "30s")
35+
c.Set("debug", true)
36+
c.Set("weight", 0.42)
37+
c.Enable("dark-mode")
38+
c.Enable("experimental-fleet")
39+
return c
40+
}
41+
42+
// --- Construction ---
43+
44+
func BenchmarkConfig_New(b *B) {
45+
b.ReportAllocs()
46+
for i := 0; i < b.N; i++ {
47+
configSinkConfig = (&Config{}).New()
48+
}
49+
}
50+
51+
// --- Settings (Set / Get) ---
52+
53+
func BenchmarkConfig_Set_Fresh(b *B) {
54+
b.ReportAllocs()
55+
for i := 0; i < b.N; i++ {
56+
cfg := (&Config{}).New()
57+
cfg.Set("key", "value")
58+
}
59+
}
60+
61+
func BenchmarkConfig_Set_Update(b *B) {
62+
cfg := configFixture()
63+
b.ReportAllocs()
64+
for i := 0; i < b.N; i++ {
65+
cfg.Set("database.host", "homelab.lthn.sh")
66+
}
67+
}
68+
69+
func BenchmarkConfig_Get_Hit(b *B) {
70+
cfg := configFixture()
71+
b.ReportAllocs()
72+
for i := 0; i < b.N; i++ {
73+
configSinkResult = cfg.Get("database.host")
74+
}
75+
}
76+
77+
func BenchmarkConfig_Get_Miss(b *B) {
78+
cfg := configFixture()
79+
b.ReportAllocs()
80+
for i := 0; i < b.N; i++ {
81+
configSinkResult = cfg.Get("noexist")
82+
}
83+
}
84+
85+
// --- Typed accessors ---
86+
87+
func BenchmarkConfig_String_Hit(b *B) {
88+
cfg := configFixture()
89+
b.ReportAllocs()
90+
for i := 0; i < b.N; i++ {
91+
configSinkString = cfg.String("database.host")
92+
}
93+
}
94+
95+
func BenchmarkConfig_Int_Hit(b *B) {
96+
cfg := configFixture()
97+
b.ReportAllocs()
98+
for i := 0; i < b.N; i++ {
99+
configSinkInt = cfg.Int("database.port")
100+
}
101+
}
102+
103+
func BenchmarkConfig_Bool_Hit(b *B) {
104+
cfg := configFixture()
105+
b.ReportAllocs()
106+
for i := 0; i < b.N; i++ {
107+
configSinkBool = cfg.Bool("debug")
108+
}
109+
}
110+
111+
func BenchmarkConfig_ConfigGet_Float64(b *B) {
112+
cfg := configFixture()
113+
b.ReportAllocs()
114+
for i := 0; i < b.N; i++ {
115+
_ = ConfigGet[float64](cfg, "weight")
116+
}
117+
}
118+
119+
// --- Feature flags ---
120+
121+
func BenchmarkConfig_Enable(b *B) {
122+
cfg := configFixture()
123+
b.ReportAllocs()
124+
for i := 0; i < b.N; i++ {
125+
cfg.Enable("dark-mode")
126+
}
127+
}
128+
129+
func BenchmarkConfig_Disable(b *B) {
130+
cfg := configFixture()
131+
b.ReportAllocs()
132+
for i := 0; i < b.N; i++ {
133+
cfg.Disable("dark-mode")
134+
}
135+
}
136+
137+
func BenchmarkConfig_Enabled_Hit(b *B) {
138+
cfg := configFixture()
139+
b.ReportAllocs()
140+
for i := 0; i < b.N; i++ {
141+
configSinkBool = cfg.Enabled("dark-mode")
142+
}
143+
}
144+
145+
func BenchmarkConfig_Enabled_Miss(b *B) {
146+
cfg := configFixture()
147+
b.ReportAllocs()
148+
for i := 0; i < b.N; i++ {
149+
configSinkBool = cfg.Enabled("noexist")
150+
}
151+
}
152+
153+
func BenchmarkConfig_EnabledFeatures(b *B) {
154+
cfg := configFixture()
155+
b.ReportAllocs()
156+
for i := 0; i < b.N; i++ {
157+
configSinkStrings = cfg.EnabledFeatures()
158+
}
159+
}
160+
161+
// --- ConfigVar[T] (per-package typed slot) ---
162+
163+
func BenchmarkConfig_NewConfigVar(b *B) {
164+
b.ReportAllocs()
165+
for i := 0; i < b.N; i++ {
166+
_ = NewConfigVar[int](42)
167+
}
168+
}
169+
170+
func BenchmarkConfig_ConfigVar_Get(b *B) {
171+
v := NewConfigVar[int](42)
172+
b.ReportAllocs()
173+
for i := 0; i < b.N; i++ {
174+
configSinkInt = v.Get()
175+
}
176+
}
177+
178+
func BenchmarkConfig_ConfigVar_Set(b *B) {
179+
v := NewConfigVar[int](42)
180+
b.ReportAllocs()
181+
for i := 0; i < b.N; i++ {
182+
v.Set(43)
183+
}
184+
}
185+
186+
func BenchmarkConfig_ConfigVar_IsSet(b *B) {
187+
v := NewConfigVar[int](42)
188+
b.ReportAllocs()
189+
for i := 0; i < b.N; i++ {
190+
configSinkBool = v.IsSet()
191+
}
192+
}
193+
194+
func BenchmarkConfig_ConfigVar_Unset(b *B) {
195+
v := NewConfigVar[int](42)
196+
b.ReportAllocs()
197+
for i := 0; i < b.N; i++ {
198+
v.Unset()
199+
}
200+
}

contract_bench_test.go

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// SPDX-License-Identifier: EUPL-1.2
2+
3+
// Benchmarks for the framework-contract primitives in contract.go.
4+
// Per AX-11 — the With* CoreOption functions are applied once per
5+
// core.New() call. The Action* contract structs (ActionServiceStartup,
6+
// ActionTaskStarted/Progress/Completed) flow across the IPC bus on
7+
// every lifecycle event. The bench gates the option-application path
8+
// and the contract-construction cost.
9+
//
10+
// Run: go test -bench='BenchmarkContract' -benchmem -run='^$' .
11+
12+
package core_test
13+
14+
import (
15+
. "dappco.re/go"
16+
)
17+
18+
// Sinks defeat compiler DCE.
19+
var (
20+
contractSinkCore *Core
21+
contractSinkOption CoreOption
22+
contractSinkMessage Message
23+
)
24+
25+
// --- New + WithOption flow ---
26+
27+
func BenchmarkContract_New_WithOptions(b *B) {
28+
b.ReportAllocs()
29+
for i := 0; i < b.N; i++ {
30+
contractSinkCore = New(
31+
WithOption("name", "bench"),
32+
WithOption("port", 9000),
33+
)
34+
}
35+
}
36+
37+
func BenchmarkContract_New_WithFullOptions(b *B) {
38+
opts := NewOptions(
39+
Option{Key: "name", Value: "bench"},
40+
Option{Key: "port", Value: 9000},
41+
Option{Key: "debug", Value: true},
42+
)
43+
b.ReportAllocs()
44+
for i := 0; i < b.N; i++ {
45+
contractSinkCore = New(WithOptions(opts))
46+
}
47+
}
48+
49+
func BenchmarkContract_New_WithServiceLock(b *B) {
50+
b.ReportAllocs()
51+
for i := 0; i < b.N; i++ {
52+
contractSinkCore = New(WithServiceLock())
53+
}
54+
}
55+
56+
// --- CoreOption constructors (closure allocation) ---
57+
58+
func BenchmarkContract_WithOption(b *B) {
59+
b.ReportAllocs()
60+
for i := 0; i < b.N; i++ {
61+
contractSinkOption = WithOption("name", "bench")
62+
}
63+
}
64+
65+
func BenchmarkContract_WithOptions(b *B) {
66+
opts := NewOptions(Option{Key: "name", Value: "bench"})
67+
b.ReportAllocs()
68+
for i := 0; i < b.N; i++ {
69+
contractSinkOption = WithOptions(opts)
70+
}
71+
}
72+
73+
func BenchmarkContract_WithName(b *B) {
74+
factory := func(c *Core) Result {
75+
return Result{Value: &struct{ id int }{id: 1}, OK: true}
76+
}
77+
b.ReportAllocs()
78+
for i := 0; i < b.N; i++ {
79+
contractSinkOption = WithName("bench", factory)
80+
}
81+
}
82+
83+
// --- Lifecycle action contracts ---
84+
85+
func BenchmarkContract_ActionServiceStartup(b *B) {
86+
b.ReportAllocs()
87+
for i := 0; i < b.N; i++ {
88+
contractSinkMessage = ActionServiceStartup{}
89+
}
90+
}
91+
92+
func BenchmarkContract_ActionServiceShutdown(b *B) {
93+
b.ReportAllocs()
94+
for i := 0; i < b.N; i++ {
95+
contractSinkMessage = ActionServiceShutdown{}
96+
}
97+
}
98+
99+
// --- Task lifecycle contracts (carry payload) ---
100+
101+
func BenchmarkContract_ActionTaskStarted(b *B) {
102+
b.ReportAllocs()
103+
for i := 0; i < b.N; i++ {
104+
contractSinkMessage = ActionTaskStarted{
105+
TaskIdentifier: "task-42",
106+
Action: "agentic.dispatch",
107+
}
108+
}
109+
}
110+
111+
func BenchmarkContract_ActionTaskProgress(b *B) {
112+
b.ReportAllocs()
113+
for i := 0; i < b.N; i++ {
114+
contractSinkMessage = ActionTaskProgress{
115+
TaskIdentifier: "task-42",
116+
Action: "agentic.dispatch",
117+
Progress: 0.5,
118+
Message: "halfway",
119+
}
120+
}
121+
}
122+
123+
func BenchmarkContract_ActionTaskCompleted(b *B) {
124+
b.ReportAllocs()
125+
for i := 0; i < b.N; i++ {
126+
contractSinkMessage = ActionTaskCompleted{
127+
TaskIdentifier: "task-42",
128+
Action: "agentic.dispatch",
129+
Result: Result{OK: true},
130+
}
131+
}
132+
}

0 commit comments

Comments
 (0)