Skip to content

PERF: Cache Route Pattern Once Per Request Across Policies #2

@MrEthical07

Description

@MrEthical07

Background:
Both cache and rate limit policies resolve route pattern independently on the same request path. On high RPS routes with chained policies, this duplicates work on a hot path.

Problem:
Route pattern extraction is repeated in internal/core/policy/cache.go and internal/core/policy/ratelimit.go, increasing per-request overhead.

Scope:

  • Introduce a per-request route pattern resolver/cache in policy flow.
  • Update cache and rate limit policies to reuse the same resolved value.
  • Add a benchmark case for chained policy execution in internal/core/policy/benchmark_test.go.

Tasks:

  • Add helper to resolve and store route pattern once per request context.
  • Replace duplicate route resolution calls in cache and rate limit policies.
  • Add benchmark coverage for cache+ratelimit chain.
  • Add regression tests for correctness.

Acceptance Criteria:

  • Route pattern is resolved at most once per request in chained policy scenarios.
  • Behavior and response semantics remain unchanged.
  • Benchmark shows reduced ns/op for policy chain path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions