optimize checkArnMatch: equality fast-path and memoized matchers#2637
optimize checkArnMatch: equality fast-path and memoized matchers#2637delthas wants to merge 2 commits into
Conversation
checkArnMatch built six RegExp objects per call (relative-id + five ARN
segments) even though most portions contain no wildcard. Since the
wildcard-translated pattern is anchored with every regExp character
escaped, testing it is equivalent to string equality for wildcard-free
portions: compare those directly and only build a RegExp for portions
containing '*', '?' or '${'.
This is the dominant CPU cost of warm authorization in Vault (V8 profile:
StringPrototypeReplace + RegExpConstructor + StringPrototypeSplit under
evaluatePolicy), measured at +18-19%% throughput / -16%% p95 on a
1000-account authz benchmark together with the matcher memoization that
follows. Behavior is unchanged, verified by differential testing against
the previous implementation.
Issue: ARSN-590
The same policy ARN patterns are matched over and over across requests (every request context x policy statement x Resource entry), but the matcher was recompiled on every call. Cache compiled matchers keyed by (caseSensitive, policyArn) in a 10000-entry LRUCache: matchers are pure functions of the key, so the cache needs no invalidation, and the LRU cap bounds the cardinality introduced by policy-variable substitution. A miss costs exactly what every call cost before. Issue: ARSN-590
Hello delthas,My role is to assist you with the merge of this Available options
Available commands
Status report is not available. |
Waiting for approvalThe following approvals are needed before I can proceed with the merge:
|
|
LGTM |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development/8.4 #2637 +/- ##
===================================================
+ Coverage 73.92% 73.95% +0.03%
===================================================
Files 229 229
Lines 18480 18509 +29
Branches 3822 3836 +14
===================================================
+ Hits 13661 13688 +27
- Misses 4814 4816 +2
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
checkArnMatchbuilt sixRegExpobjects per call (regex-escape + compile for the relative-id and each of the five ARN segments), for every (request context × policy statement × Resource entry). A V8 profile of Vault under warm authorization load showed this as the worker's dominant CPU cost (StringPrototypeReplace+RegExpConstructor+StringPrototypeSplitunderevaluatePolicy, plus the resulting GC churn).Two commits:
RegExpfor portions containing*,?or${.(caseSensitive, policyArn); cache them in a 10000-entryLRUCache. No invalidation needed; the LRU cap bounds the cardinality introduced by policy-variable substitution; a miss costs what every call cost before.Behavior-preserving: verified by differential testing against the previous implementation over a matrix of literal/wildcard patterns, case-insensitive mode, policy-variable literals (
${*}), empty-account service ARNs, and malformed ARNs — zero differences. Measured on a 1000-account Vault authz benchmark (warm, drift-controlled A→B→A): +18–19% throughput, p95 −16%.Issue: ARSN-590