Optimize O(n²) algorithms and reduce redundant iterations#2778
Conversation
📝 WalkthroughWalkthroughRefactors duplicate-model processing to use per-module sets and batch removals, adjusts self-reference detection in JSON Schema array parsing to a streaming check, and changes OpenAPI discriminator handling to a two-phase collection that resolves allOf-derived subtypes after initial discriminator discovery. Changes
Sequence Diagram(s)(omitted — changes are internal parser/data structure refinements without a new multi-component sequential flow) Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
🧰 Additional context used🧬 Code graph analysis (1)src/datamodel_code_generator/parser/openapi.py (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
🔇 Additional comments (2)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2778 +/- ##
==========================================
- Coverage 99.48% 99.48% -0.01%
==========================================
Files 87 87
Lines 12897 12908 +11
Branches 1543 1547 +4
==========================================
+ Hits 12831 12841 +10
Misses 35 35
- Partials 31 32 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
CodSpeed Performance ReportMerging #2778 will not alter performanceComparing Summary
Footnotes
|
Performance optimizations: 1. Batch model removal in __create_shared_module_from_duplicates: - Use sets for O(1) membership checks - Collect models to remove and batch process at end - Avoids O(n²) list.remove() calls in loops 2. O(1) parameter name duplicate detection: - Use set to track seen parameter names - Replaces O(n) any() scan for each parameter 3. Single-pass discriminator schema collection: - Merge two iterations into one - Collect allOf refs during first pass - Only iterate schemas with allOf for subtype resolution 4. Early-exit self-reference check: - Replace list comprehension with any() generator - Stops at first match instead of building full list
c66d12a to
c04171a
Compare
Breaking Change AnalysisResult: No breaking changes detected Reasoning: PR #2778 contains pure performance optimizations with no breaking changes. The changes include: (1) Batch model removal using sets for O(1) lookups instead of O(n) list operations - same models are removed, just more efficiently; (2) Early-exit self-reference check using any() generator instead of list comprehension - identical boolean result; (3) O(1) parameter name duplicate detection using a set instead of any() scan - same validation behavior and exception; (4) Single-pass discriminator schema collection merging two iterations into one - same final data collected. All changes are algorithmic optimizations that produce identical output, which is why no test changes were needed. The generated code output, CLI/API behavior, templates, and error handling all remain unchanged. This analysis was performed by Claude Code Action |
Summary by CodeRabbit
Performance Improvements
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.