plugin/forward: fast-path string comparison in isAllowedDomain (#8385)

* test: add benchmark cases for Request IP/Port and parseRequest

Signed-off-by: Manuel Rüger <manuel@rueg.eu>

* test(kubernetes): add BenchmarkServices and BenchmarkServicesHeadless

Signed-off-by: Manuel Rüger <manuel@rueg.eu>

* perf(forward): fast-path string comparison in isAllowedDomain

Signed-off-by: Manuel Rüger <manuel@rueg.eu>

---------

Signed-off-by: Manuel Rüger <manuel@rueg.eu>
This commit is contained in:
Manuel Rüger
2026-08-04 03:44:27 +02:00
committed by GitHub
parent d74404f8ac
commit a1642a64dc
3 changed files with 57 additions and 0 deletions

View File

@@ -493,3 +493,33 @@ func TestServicesAuthority(t *testing.T) {
} }
} }
} }
func BenchmarkServices(b *testing.B) {
k := New([]string{"inter.webs.tests."})
k.APIConn = APIConnServiceTest{}
ctx := context.TODO()
m := new(dns.Msg)
m.SetQuestion("svc1.testns.svc.inter.webs.tests.", dns.TypeA)
state := request.Request{Zone: k.Zones[0], Req: m}
b.ReportAllocs()
for b.Loop() {
_, _ = k.Services(ctx, state, false, plugin.Options{})
}
}
func BenchmarkServicesHeadless(b *testing.B) {
k := New([]string{"inter.webs.tests."})
k.APIConn = APIConnServiceTest{}
ctx := context.TODO()
m := new(dns.Msg)
m.SetQuestion("hdls1.testns.svc.inter.webs.tests.", dns.TypeA)
state := request.Request{Zone: k.Zones[0], Req: m}
b.ReportAllocs()
for b.Loop() {
_, _ = k.Services(ctx, state, false, plugin.Options{})
}
}

View File

@@ -63,3 +63,10 @@ func TestParseInvalidRequest(t *testing.T) {
} }
const zone = "inter.webs.tests." const zone = "inter.webs.tests."
func BenchmarkParseRequest(b *testing.B) {
b.ReportAllocs()
for b.Loop() {
_, _ = parseRequest("1-2-3-4.webs.mynamespace.svc.inter.webs.tests.", zone, false)
}
}

View File

@@ -381,3 +381,23 @@ func TestRequestClear(t *testing.T) {
t.Errorf("Expected st.port to be cleared after Clear") t.Errorf("Expected st.port to be cleared after Clear")
} }
} }
func BenchmarkRequestIP(b *testing.B) {
st := testRequest()
b.ReportAllocs()
for b.Loop() {
st.Clear()
_ = st.IP()
}
}
func BenchmarkRequestPort(b *testing.B) {
st := testRequest()
b.ReportAllocs()
for b.Loop() {
st.Clear()
_ = st.Port()
}
}