perf: batch cache check to reduce lock contention in Check endpoint#382
Merged
perf: batch cache check to reduce lock contention in Check endpoint#382
Conversation
f727bd6 to
71606b8
Compare
Two optimizations to reduce lock contention in the Check endpoint: 1. Async cache update: UpdateCacheWithChecks now runs in a background goroutine by default (configurable via AUTHZCACHE_ASYNC_CACHE_UPDATE), so the write lock doesn't block concurrent readers. 2. Batch cache check: New CheckRelations method acquires the read lock once for the entire batch instead of per-relation, eliminating N-1 redundant lock acquire/release cycles. Combined, these reduce p50 latency by ~54% for 5000-relation checks under concurrent load. Resolves descope/etc#14193 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
71606b8 to
9a99e02
Compare
d93abef to
676b986
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
orius123
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
Resolves: https://github.com/descope/etc/issues/14193
Summary
Replaces the per-relation
CheckRelationloop (which acquiredRLock/RUnlockN times per request) with a singleCheckRelationscall that holds oneRLockfor the entire batch. This eliminates redundant lock acquisitions and significantly reduces contention under concurrent load.Changes
CheckRelations(ctx, relations)batch method toProjectAuthzCacheinterface and implementation — acquires a singleRLockfor all relation lookupsCheckRelation(single-relation method) from the interfaceCheckendpoint to use the new batch methodBenchmark
Simulated concurrent load with 50% cache hits and 1ms SDK latency:
Prior to this change (with N separate
RLockacquisitions), contention under concurrent load was ~34–40% higher at 1000+ relations, which could be the source of the latency mentioned in the parent issue