From d9a258ae44d781ed7bdeacf82f84ea9f8d33424c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Tue, 10 Nov 2026 00:26:44 +0900 Subject: [PATCH] perf(core): build the signed service route prefixes once (#7802) Five route filters test the path of every request of every service. Each test built the root path plus a slash, and each filter built its internal prefix test again on every request. That was about 350 bytes per request. --- .../java/io/floci/aws/core/common/SignedServiceRoute.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/floci/aws/core/common/SignedServiceRoute.java b/src/main/java/io/floci/aws/core/common/SignedServiceRoute.java index b56fc91bab..20a81bf139 100644 --- a/src/main/java/io/floci/aws/core/common/SignedServiceRoute.java +++ b/src/main/java/io/floci/aws/core/common/SignedServiceRoute.java @@ -29,6 +29,7 @@ public final class SignedServiceRoute { private final ResolvedServiceCatalog catalog; private final Set externalKeys; private final String internalPrefix; + private final Predicate internalPaths; private final Predicate publicPaths; /** @@ -58,12 +59,15 @@ public final class SignedServiceRoute { this.catalog = catalog; this.externalKeys = Set.copyOf(externalKeys); this.internalPrefix = internalPrefix; + this.internalPaths = under(internalPrefix); this.publicPaths = publicPaths; } /** Matches {@code root} itself and every path beneath it. */ public static Predicate under(String root) { - return path -> path.equals(root) || path.startsWith(root + "/"); + // Every request of every service runs these tests, so the prefix is built once. + String beneath = root + "/"; + return path -> path.equals(root) || path.startsWith(beneath); } /** @@ -80,7 +84,7 @@ public final class SignedServiceRoute { String path = ctx.getUriInfo().getPath(); String normalizedPath = path.startsWith("/") ? path : "/" + path; - if (under(internalPrefix).test(normalizedPath)) { + if (internalPaths.test(normalizedPath)) { if (!signedForService(ctx)) { ctx.abortWith(invalidBucketName()); }