Skip to content

⚡ Bolt: Optimize Listing Audit nested loop lookup#37

Open
projectamazonph wants to merge 1 commit into
mainfrom
refactor/bolt-optimize-listing-audit-367519118260146446
Open

⚡ Bolt: Optimize Listing Audit nested loop lookup#37
projectamazonph wants to merge 1 commit into
mainfrom
refactor/bolt-optimize-listing-audit-367519118260146446

Conversation

@projectamazonph

@projectamazonph projectamazonph commented Jul 17, 2026

Copy link
Copy Markdown
Owner

💡 What: Convert O(NM) nested loop array .find() lookups into O(1) Map lookups in findingsAccuracy and severityCalibration inside src/engine/listing-audit/engine.ts.
🎯 Why: This resolves a potential bottleneck when grading interactive scenario submissions, ensuring response times remain sub-millisecond.
📊 Impact: Reduces grading time complexity from O(N
M) to O(N+M).
🔬 Measurement: Verified with a full suite of unit tests in src/engine/listing-audit/engine.test.ts.


PR created automatically by Jules for task 367519118260146446 started by @projectamazonph

Summary by CodeRabbit

  • Performance

    • Improved Listing Audit grading performance, especially for submissions with many findings.
  • Bug Fixes

    • Added coverage for successful and unsuccessful grading scenarios.
    • Improved automatic detection of listing differences across titles, bullets, images, and A+ content.

Co-authored-by: projectamazonph <286085559+projectamazonph@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Listing Audit grading replaces repeated reference-finding scans with field-keyed Map lookups. New Vitest coverage validates grading outcomes and generated findings for listing fields, while a performance journal entry documents the complexity change.

Changes

Listing Audit optimization

Layer / File(s) Summary
Optimize reference finding lookups
.jules/bolt.md, src/engine/listing-audit/engine.ts
findingsAccuracy and severityCalibration use precomputed field-keyed maps, preserving the first entry for duplicate fields.
Cover grading and auto-finding behavior
src/engine/listing-audit/engine.test.ts
Tests cover successful grading, failed grading with empty findings, and generated title, bullets, images, and A+ findings.

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

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: optimizing Listing Audit lookup logic in nested loops.
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.
✨ 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 refactor/bolt-optimize-listing-audit-367519118260146446

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
src/engine/listing-audit/engine.ts (1)

116-127: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the duplicated Map-building logic into a shared helper.

Both findingsAccuracy (lines 88-93) and severityCalibration (lines 117-122) contain identical Map-construction code. Extracting a helper eliminates the duplication and prevents the two copies from diverging. As a secondary improvement, typing the Map key as ListingAuditFinding['field'] instead of string would be more type-safe.

♻️ Proposed helper extraction
+function buildFieldMap(
+  findings: ListingAuditFinding[],
+): Map<ListingAuditFinding['field'], ListingAuditFinding> {
+  const map = new Map<ListingAuditFinding['field'], ListingAuditFinding>();
+  for (const rf of findings) {
+    if (!map.has(rf.field)) {
+      map.set(rf.field, rf);
+    }
+  }
+  return map;
+}
+
 function findingsAccuracy(
   student: ListingAuditFinding[],
   ref: ListingAuditFinding[]
 ): CriterionResult {
   if (student.length === 0) {
     return binaryCriterion('findings_accuracy', false, PASS, 'No findings submitted.');
   }

-  // Bolt optimization: Map reference findings by field to replace O(N*M) nested lookups with O(1) lookups
-  const refMap = new Map<string, ListingAuditFinding>();
-  for (const rf of ref) {
-    if (!refMap.has(rf.field)) {
-      refMap.set(rf.field, rf);
-    }
-  }
+  const refMap = buildFieldMap(ref);

   let truePositives = 0;

And in severityCalibration:

-  // Bolt optimization: Map reference findings by field to replace O(N*M) nested lookups with O(1) lookups
-  const refMap = new Map<string, ListingAuditFinding>();
-  for (const rf of ref) {
-    if (!refMap.has(rf.field)) {
-      refMap.set(rf.field, rf);
-    }
-  }
+  const refMap = buildFieldMap(ref);
🤖 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 `@src/engine/listing-audit/engine.ts` around lines 116 - 127, Extract the
duplicated reference-finding Map construction from findingsAccuracy and
severityCalibration into a shared helper, then use that helper in both methods
while preserving first-entry-per-field behavior. Type the helper’s Map key as
ListingAuditFinding['field'] instead of string, and remove the duplicated inline
loops.
src/engine/listing-audit/engine.test.ts (1)

86-96: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a test for duplicate reference fields.

The core behavior change of the Map optimization is how duplicate field entries in referenceFindings are handled (first entry wins). A test with duplicate reference fields would verify this edge case is preserved correctly and serve as a regression guard.

🤖 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 `@src/engine/listing-audit/engine.test.ts` around lines 86 - 96, Add a
regression test alongside generateAutoFindings that supplies referenceFindings
with duplicate field entries and verifies the first entry wins. Assert the
resulting finding uses the first reference value while preserving the existing
behavior for non-duplicate fields.
🤖 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 `@src/engine/listing-audit/engine.test.ts`:
- Around line 86-96: Add a regression test alongside generateAutoFindings that
supplies referenceFindings with duplicate field entries and verifies the first
entry wins. Assert the resulting finding uses the first reference value while
preserving the existing behavior for non-duplicate fields.

In `@src/engine/listing-audit/engine.ts`:
- Around line 116-127: Extract the duplicated reference-finding Map construction
from findingsAccuracy and severityCalibration into a shared helper, then use
that helper in both methods while preserving first-entry-per-field behavior.
Type the helper’s Map key as ListingAuditFinding['field'] instead of string, and
remove the duplicated inline loops.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d820748-9f7b-4298-8446-73aa0fc35ef4

📥 Commits

Reviewing files that changed from the base of the PR and between 70c035a and 5f59e25.

📒 Files selected for processing (3)
  • .jules/bolt.md
  • src/engine/listing-audit/engine.test.ts
  • src/engine/listing-audit/engine.ts

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant