⚡ Bolt: Optimize Listing Audit nested loop lookup#37
Conversation
Co-authored-by: projectamazonph <286085559+projectamazonph@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
📝 WalkthroughWalkthroughListing Audit grading replaces repeated reference-finding scans with field-keyed ChangesListing Audit optimization
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/engine/listing-audit/engine.ts (1)
116-127: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the duplicated Map-building logic into a shared helper.
Both
findingsAccuracy(lines 88-93) andseverityCalibration(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 asListingAuditFinding['field']instead ofstringwould 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 winConsider adding a test for duplicate reference fields.
The core behavior change of the Map optimization is how duplicate
fieldentries inreferenceFindingsare 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
📒 Files selected for processing (3)
.jules/bolt.mdsrc/engine/listing-audit/engine.test.tssrc/engine/listing-audit/engine.ts
💡 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(NM) 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
Bug Fixes