Skip to content

optimize checkArnMatch: equality fast-path and memoized matchers#2637

Draft
delthas wants to merge 2 commits into
development/8.4from
improvement/ARSN-590/optimize-checkarnmatch
Draft

optimize checkArnMatch: equality fast-path and memoized matchers#2637
delthas wants to merge 2 commits into
development/8.4from
improvement/ARSN-590/optimize-checkarnmatch

Conversation

@delthas

@delthas delthas commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

checkArnMatch built six RegExp objects 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 + StringPrototypeSplit under evaluatePolicy, plus the resulting GC churn).

Two commits:

  1. Equality fast-path — a wildcard-free portion translates to a fully-escaped, anchored regExp, so testing it is equivalent to string equality: compare those portions directly and only build a RegExp for portions containing *, ? or ${.
  2. Matcher memoization — compiled matchers are pure functions of (caseSensitive, policyArn); cache them in a 10000-entry LRUCache. 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

delthas added 2 commits June 10, 2026 15:38
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
@bert-e

bert-e commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Hello delthas,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request TBA
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e

bert-e commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Waiting for approval

The following approvals are needed before I can proceed with the merge:

  • the author

  • 2 peers

@claude

claude Bot commented Jun 10, 2026

Copy link
Copy Markdown

LGTM

The equality fast-path correctly skips RegExp construction for wildcard-free portions, and the memoization via LRUCache is safe (non-global regexes, no statefulness, correct cache key partitioning by case-sensitivity). Case-insensitive handling for segments matches the prior behavior (only the relativeId is lowercased, not the five ARN segments — consistent with their standardized casing in practice). The hasWildcards guard conservatively routes any ${ through the regex path, preserving correct handling of ${*}, ${?}, and ${$}. Tests cover literal matching, wildcard matching, ${ escapes, utapi empty-account exemption, memoization consistency, and cache eviction — good coverage of the optimization invariants.

Review by Claude Code

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.95%. Comparing base (6a5ee64) to head (1078a4c).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants