Skip to content

perf(core): add core improvements - #1091

Merged
sauraww merged 1 commit into
mainfrom
prefix-filter-optimisation
Aug 14, 2026
Merged

perf(core): add core improvements#1091
sauraww merged 1 commit into
mainfrom
prefix-filter-optimisation

Conversation

@sauraww

@sauraww sauraww commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Problem

Several hot-path and parsing details from the user-cohort work were useful independently of the full feature:

  • Condition matching used nested branching for every dimension.
  • Local-cohort evaluation used loosely grouped _-prefixed helpers and created avoidable intermediate collections.
  • DimensionType::from_str indexed split input directly, so malformed cohort types such as LOCAL_COHORT could panic.

Solution

  • Rewrote condition matching with a short-circuiting iterator while preserving exact and variantIds behavior.
  • Encapsulated local-cohort evaluation in a private module, removed _-prefixed helper names, and avoided temporary collections where the iterator can be consumed directly.
  • Made dimension-type parsing validate the complete input shape before accessing cohort information. Malformed or empty cohort types now return an error instead of panicking.

The earlier prefix-filter optimization and its benchmark/documentation changes are not part of this PR.

Validation

  • cargo test -p superposition_types -p superposition_core
  • cargo test -p superposition_provider
  • Targeted rustfmt --check for all changed files

Environment variable changes

None.

Pre-deployment activity

None.

Post-deployment activity

None.

API changes

No endpoint or valid-input API changes. Invalid dimension-type strings now return an error instead of potentially panicking.

Endpoint Method Request body Response body
N/A N/A No changes No changes

Possible issues in the future

Context resolution still performs a linear scan over configured conditions. This PR reduces per-condition overhead but does not add indexing or caching.

Copilot AI review requested due to automatic review settings July 10, 2026 19:20
@sauraww
sauraww requested a review from a team as a code owner July 10, 2026 19:20
@semanticdiff-com

semanticdiff-com Bot commented Jul 10, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 74c12d5f-790e-4b21-bac8-c33a4bd4c61e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

eval_config and eval_config_with_reasoning now filter prefixes directly while resolving overrides and default keys. Resolve benchmarks compare borrowed and cloned prefix paths, and performance documentation records the results.

Changes

Prefix-filtered resolution

Layer / File(s) Summary
Direct prefix filtering in config evaluation
crates/superposition_core/src/config.rs
Configuration evaluation uses HashSet prefix filters to select default and override keys during resolution without constructing a temporary Config.
Prefix resolution benchmark paths
crates/superposition_core/benches/resolve.rs
Criterion benchmarks compare unfiltered borrowed resolution, prefix-filtered borrowed resolution, and pre-filtered cloned resolution.
Performance analysis updates
docs/misc/PERF_ANALYSIS_RESOLUTION.md
Documentation describes the updated resolution paths and records prefix-filter benchmark estimates.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • juspay/superposition#1079: Earlier resolve hot-path and override-selection refactoring related to this prefix-filtering change.

Suggested reviewers: knutties, Datron, mahatoankitkumar

Poem

I’m a rabbit tuning keys with care,
Filtering prefixes through the air.
Borrowed paths now hop ahead,
Cloned paths trail where tests are led.
Benchmarks sparkle, docs explain—
Faster burrows through the chain!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title indicates a core performance change but does not identify the prefix-filtered configuration resolution optimization. Specify the optimized behavior, such as prefix-filtered configuration resolution, instead of using the generic phrase "core improvements".
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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 prefix-filter-optimisation

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves superposition_core configuration resolution performance for prefix-filtered requests by removing the full Config deep-clone and instead applying prefix filtering while collecting override keys and filtering the already-owned default config directly. Adds benchmark coverage and documents the before/after results for the prefix-filtered path.

Changes:

  • Update eval_config / eval_config_with_reasoning to resolve against borrowed contexts/overrides for both unfiltered and prefix-filtered requests.
  • Apply prefix filtering inside get_overrides (skip non-matching override keys) and filter default config keys before merging.
  • Expand the Criterion benchmark and performance analysis doc with prefix-filtered results and comparison against the previous cloned approach.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
docs/misc/PERF_ANALYSIS_RESOLUTION.md Updates the perf write-up to reflect the new borrowed prefix-filter path and adds prefix benchmark results.
crates/superposition_core/src/config.rs Refactors prefix-filtered resolution to avoid cloning full config; adds prefix-filter helpers and threads prefix filtering into override collection.
crates/superposition_core/benches/resolve.rs Adds prefix-filtered benchmark variants comparing pre-optimization cloned behavior vs optimized borrowed behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/superposition_core/src/config.rs Outdated
Comment on lines +22 to +24
let filter_prefixes: Option<HashSet<String>> = filter_prefixes
.filter(|prefixes| !prefixes.is_empty())
.map(HashSet::from_iter);
Comment thread crates/superposition_core/src/config.rs Outdated
Comment on lines +129 to +142
match merge_strategy {
MergeStrategy::REPLACE => {
for (key, value) in overriden_value.iter() {
if !matches_prefix_filter(key, prefix_filter) {
continue;
}
required_overrides.insert(key.clone(), value.clone());
}
}
MergeStrategy::MERGE => {
for (key, value) in overriden_value.iter() {
if !matches_prefix_filter(key, prefix_filter) {
continue;
}

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
crates/superposition_core/src/config.rs (1)

22-41: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

eval_config and eval_config_with_reasoning are now identical — extract shared logic.

After this refactor, both functions have byte-for-byte identical bodies (same filter_prefixes conversion, get_overrides call with None callback, filter_config_keys_by_prefix, and merge_overrides_on_default_config). Any future bug fix or logic change must be applied in both places. Since eval_config_with_reasoning no longer adds reasoning metadata (confirmed by the test at line 210), it can simply delegate to eval_config.

♻️ Proposed delegation
 pub fn eval_config_with_reasoning(
     default_config: Map<String, Value>,
     contexts: &[Context],
     overrides: &HashMap<String, Overrides>,
     dimensions: &HashMap<String, DimensionInfo>,
     query_data: &Map<String, Value>,
     merge_strategy: MergeStrategy,
     filter_prefixes: Option<Vec<String>, // Optional prefix filtering
 ) -> Result<Map<String, Value>, String> {
-    let modified_query_data = evaluate_local_cohorts(dimensions, query_data);
-
-    let filter_prefixes: Option<HashSet<String>> = filter_prefixes
-        .filter(|prefixes| !prefixes.is_empty())
-        .map(HashSet::from_iter);
-
-    let overrides_map = get_overrides(
-        &modified_query_data,
-        contexts,
-        overrides,
-        &merge_strategy,
-        filter_prefixes.as_ref(),
-        None,
-    )?;
-
-    let mut result_config = match &filter_prefixes {
-        Some(prefixes) => filter_config_keys_by_prefix(default_config, prefixes),
-        None => default_config,
-    };
-    merge_overrides_on_default_config(&mut result_config, overrides_map, &merge_strategy);
-
-    Ok(result_config)
+    eval_config(
+        default_config,
+        contexts,
+        overrides,
+        dimensions,
+        query_data,
+        merge_strategy,
+        filter_prefixes,
+    )
 }

Also applies to: 55-74

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/superposition_core/src/config.rs` around lines 22 - 41, Extract the
duplicated implementation from eval_config_with_reasoning and make it delegate
directly to eval_config, preserving the existing parameters and return behavior.
Remove the repeated filter_prefixes conversion, get_overrides call, config
filtering, and merge logic so these operations remain maintained only in
eval_config.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/superposition_core/src/config.rs`:
- Around line 22-41: Extract the duplicated implementation from
eval_config_with_reasoning and make it delegate directly to eval_config,
preserving the existing parameters and return behavior. Remove the repeated
filter_prefixes conversion, get_overrides call, config filtering, and merge
logic so these operations remain maintained only in eval_config.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 04d172dc-6302-40a9-93c8-6877414bdced

📥 Commits

Reviewing files that changed from the base of the PR and between 77e840c and e491863.

📒 Files selected for processing (3)
  • crates/superposition_core/benches/resolve.rs
  • crates/superposition_core/src/config.rs
  • docs/misc/PERF_ANALYSIS_RESOLUTION.md

@sauraww sauraww added the P0 label Jul 27, 2026
@sauraww
sauraww force-pushed the prefix-filter-optimisation branch 3 times, most recently from b291c97 to 7a515c6 Compare August 6, 2026 10:55
@sauraww sauraww changed the title perf(core): avoid config clones in prefix-filtered resolution perf(core): add core improvements Aug 6, 2026
@sauraww
sauraww force-pushed the prefix-filter-optimisation branch 3 times, most recently from 4a48237 to 52573a0 Compare August 13, 2026 13:28
@sauraww
sauraww force-pushed the prefix-filter-optimisation branch from 52573a0 to b2454c0 Compare August 13, 2026 13:45
@sauraww
sauraww added this pull request to the merge queue Aug 14, 2026
Merged via the queue into main with commit ca02a21 Aug 14, 2026
35 of 48 checks passed
@sauraww
sauraww deleted the prefix-filter-optimisation branch August 14, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants