Skip to content

feat: add query plan cache#3219

Draft
jzelinskie wants to merge 1 commit into
authzed:mainfrom
jzelinskie:outline-cache
Draft

feat: add query plan cache#3219
jzelinskie wants to merge 1 commit into
authzed:mainfrom
jzelinskie:outline-cache

Conversation

@jzelinskie

Copy link
Copy Markdown
Member

Description

Introduces a queryPlanCache that caches parsed schemas and compiled outlines behind singleflight
groups, replacing the per-request schema load and outline build in checkPermission, lookupResources, and lookupSubjects query plan paths.

Key correctness considerations:

  • Bypass-sentinel schema hashes (transactions, dev mode, tests) skip both cache and singleflight to avoid coalescing requests that may read from different datastore revisions.
  • MaxCost accounts for the entryWeight overhead (key string length) so entries are not immediately evicted.
  • ApplyAdvisor clones CanonicalKeys before mutation so cached outlines are not corrupted by downstream advisor passes.

Testing

Full consistency tests should handle this.
Just a thought now is maybe we'd want metrics on the cache hits for this.

Introduces a queryPlanCache that caches parsed
schemas and compiled outlines behind singleflight
groups, replacing the per-request schema load and
outline build in checkPermission, lookupResources,
and lookupSubjects query plan paths.

Key correctness considerations:
- Bypass-sentinel schema hashes (transactions,
  dev mode, tests) skip both cache and singleflight
  to avoid coalescing requests that may read from
  different datastore revisions.
- MaxCost accounts for the entryWeight overhead
  (key string length) so entries are not
  immediately evicted.
- ApplyAdvisor clones CanonicalKeys before mutation
  so cached outlines are not corrupted by
  downstream advisor passes.
@jzelinskie jzelinskie added the area/perf Affects performance or scalability label Jul 8, 2026
@github-actions github-actions Bot added area/api v1 Affects the v1 API area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Jul 8, 2026
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/services/v1/queryplan_cache.go 85.23% 8 Missing and 5 partials ⚠️
pkg/query/advisor.go 84.62% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

area/api v1 Affects the v1 API area/perf Affects performance or scalability area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant