Reuse cached GitHub organization members when building role groups - #304
Reuse cached GitHub organization members when building role groups#304hosom wants to merge 1 commit into
Conversation
Read the organization membership hash once while constructing a role group. This avoids repeatedly executing the deep HashOf return contract for every username in the organization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5b8ed060-ed02-4402-b5e1-af407bcb2f61
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review issues were identified.
Review tier: Lite (auto)
Findings: None
Note
Copilot is running an experiment and ran this review at Lite.
What changed in this PR
Optimizes GitHub organization role-group construction by reading the cached membership hash once.
Changes:
- Reuses one
org_membersresult during filtering. - Strengthens the regression test to require exactly one lookup.
| File | Description |
|---|---|
spec/unit/entitlements/backend/github_org/provider_spec.rb |
Verifies org_members is accessed once. |
lib/entitlements/backend/github_org/provider.rb |
Filters members through a single hash traversal. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Live production-shaped confirmationA local gem built from this PR was vendored alongside github/entitlements-app#78 in github/entitlements#141320. CPU profileDirect StackProf comparison using the same 1ms CPU profiler:
Unprofiled calculation timing
The average end-to-end calculation improvement is 11.98s / 2.4%. Wall time remains noisy because GitHub, AAD, LDAP, and cache I/O occur within the calculation phase, but the CPU profile isolates and confirms the intended optimization. All provider repository CI checks, including acceptance tests, are green. |
Summary
Read the cached GitHub organization membership hash once when constructing a role group instead of retrieving it once per username.
Problem
GitHubOrg::Provider#role_to_groupcurrently does this:org_membershas aHashOf[String => String]return contract. Although the underlying data is cached, every accessor call deeply validates all keys and values. Calling the accessor once per username therefore amplifies an O(n) operation into O(n²) validation and allocation work.A live
github/entitlementsCPU profile attributed:Contracts::Builtin::HashOf#valid?Contracts::CallWith#call_with_innerThe dominant
HashOfstack wasGitHubOrg::Provider#read→role_to_group→org_members.Fix
Capture
org_membersonce and select matching hash entries in one traversal:This preserves the existing return contract and output while reducing deep membership-hash validation to once per role group. The regression test now requires exactly one
org_memberscall.Validation
git diff --checkA locally built gem from this PR will be tested in the production-shaped
github/entitlementsbenchmark PR to measure the live impact.