perf(jans-cedarling): reduce clones through Arc sharing by dagregi · Pull Request #14173 · JanssenProject/jans (original) (raw)
📝 Walkthrough
Walkthrough
This PR optimizes the Cedar authorization and entity-building pipeline by restructuring data ownership patterns: default entities move to Arc-wrapped storage, pushed-data transfers ownership rather than being borrowed, and entity builders use stack-allocated arrays and slices for fixed-arity inputs.
Changes
Allocation Optimizations
| Layer / File(s) | Summary |
|---|---|
| Default Entities Arc Wrapping src/common/default_entities.rs, src/common/default_entities_limits.rs | DefaultEntities.inner is wrapped in Arc<HashMap<EntityUid, Entity>> instead of owned directly. Constructors use Arc::new(...) to wrap the map on creation. Validation and test code updated to iterate via entities.inner.iter() and construct Arc-wrapped instances. |
| Pushed Data Ownership Transfer and Arc-Aware Entity Extraction src/authz/build_ctx.rs, src/authz/mod.rs | build_context and build_multi_issuer_context now take pushed_data as an owned HashMap<String, Value> (not borrowed), eliminating intermediate clones. Context.data is built directly via serde_json::Map::from_iter(pushed_data). Authorization flows (authorize_multi_issuer, authorize_unsigned) pass pushed-data by value. Default entity extraction uses Arc::try_unwrap to take ownership when uniquely held, otherwise clones. |
| Entity Building Stack Allocations src/entity_builder/build_principal_entity.rs, src/entity_builder/build_principal_entity/unsigned.rs, src/entity_builder/build_multi_issuer_entity.rs | Principal entity building accepts attrs_srcs as a borrowed slice &[AttrSrc] instead of owned Vec. Unsigned flow builds id_srcs and attrs_srcs as fixed-size arrays and passes references. Multi-issuer entity building introduces RESERVED_CLAIMS constant for filtering, replaces entity_id_srcs vec! with a single-element array, and refactors all_claims construction to preallocate capacity and extend from the claims iterator. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
- JanssenProject/jans#13539: Both PRs modify
build_multi_issuer_entity.rsreserved-claims handling viafilter_reserved_claimsfor multi-issuer entity attribute construction. - JanssenProject/jans#14084: Both PRs update multi-issuer entity construction in
build_multi_issuer_entity.rs, particularlybuild_single_token_entitylogic for entity id source resolution from trusted issuer metadata.
Suggested labels
kind-enhancement, comp-jans-cedarling
Suggested reviewers
- olehbozhok
- tareknaser
- haileyesus2433 🚥 Pre-merge checks | ✅ 5 ✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title 'perf(jans-cedarling): reduce clones through Arc sharing' accurately and concisely summarizes the main change: performance optimization by using Arc to share data and reduce cloning operations. |
| Description check | ✅ Passed | The description follows the template structure with Prepare section, Target issue (#14030), Implementation Details explaining why new dependencies were avoided, and Test & Documentation checklist. Author confirms no doc impact and marks static code analysis as completed. |
| Linked Issues check | ✅ Passed | The PR addresses issue #14030's stated performance optimization goals: Arc wrapping of DefaultEntities inner HashMap, passing pushed_data by value instead of reference, RESERVED_CLAIMS constant for efficient claim filtering, and SmallVec-like stack allocation patterns for fixed-arity inputs. |
| Out of Scope Changes check | ✅ Passed | All changes directly support the linked issue #14030 performance objectives: Arc usage for shared ownership, value vs reference parameter passing, reserved claims optimization, and stack allocation for fixed-arity inputs. No unrelated modifications detected. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches 📝 Generate docstrings
- Create stacked PR
- Commit on current branch 🧪 Generate unit tests (beta)
- Create PR with unit tests
- Commit unit tests in branch
jans-cedarling-14030
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands and usage tips.