Skip to content

Skip unused formatter construction#3599

Merged
koxudaxi merged 2 commits into
mainfrom
agent/skip-unused-formatter
Jul 11, 2026
Merged

Skip unused formatter construction#3599
koxudaxi merged 2 commits into
mainfrom
agent/skip-unused-formatter

Conversation

@koxudaxi

@koxudaxi koxudaxi commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Performance Improvements

    • Improved generation speed when formatting is explicitly disabled by conditionally skipping formatter setup.
  • Bug Fixes

    • Ensured custom formatters still run when an explicit empty formatter list is provided.
    • Preserved parser formatter-builder hooks across configurations, including subclassing and runtime overrides.
  • Tests

    • Added regression and integration coverage for empty formatter behavior, including validation of fast-path output and formatter import skipping in a fresh process.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1466314d-1b4c-4965-acfd-a124ac3edbac

📥 Commits

Reviewing files that changed from the base of the PR and between dd9e1dc and 1a0087d.

📒 Files selected for processing (1)
  • src/datamodel_code_generator/parser/base.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/datamodel_code_generator/parser/base.py

📝 Walkthrough

Walkthrough

Changes

Parser formatting now skips default formatter construction when formatters=[], no custom formatter is configured, and the formatter builder is unmodified. Custom formatters and overridden builder hooks remain active, with integration and subprocess regression tests covering the behavior.

Formatter behavior

Layer / File(s) Summary
Conditional formatter construction
src/datamodel_code_generator/parser/base.py
Parser.parse() conditionally builds and stores a code formatter while preserving custom and overridden builder behavior.
Empty formatter fast path validation
tests/main/test_cli_fast_paths.py
A subprocess probe verifies generation with formatters=[] avoids importing the formatter module and matches expected output.
Custom formatter and builder-hook coverage
src/datamodel_code_generator/parser/base.py, tests/main/test_main_general.py, tests/data/expected/main/*formatter*
Integration tests and generated expectations cover empty formatters, custom formatters, subclass builder overrides, and instance-level builder replacements.

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

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant generate
  participant Parser.parse
  participant CodeFormatter
  Caller->>generate: generate with formatters=[]
  generate->>Parser.parse: parse input schema
  Parser.parse->>Parser.parse: inspect formatter configuration
  Parser.parse->>CodeFormatter: build formatter when custom or overridden
  Parser.parse-->>Caller: generated model output
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: avoiding unnecessary formatter construction.
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 agent/skip-unused-formatter

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.

@github-actions

Copy link
Copy Markdown
Contributor

📚 Docs Preview: https://pr-3599.datamodel-code-generator.pages.dev

@codspeed-hq

codspeed-hq Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 25.46%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 13 regressed benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_perf_multiple_files_input 2.5 s 3.6 s -28.91%
WallTime test_perf_large_models_pydantic_v2_builtin 661.1 ms 901 ms -26.63%
WallTime test_perf_deep_nested 3.7 s 5.1 s -26.55%
WallTime test_perf_all_options_enabled 3.9 s 5.3 s -26.32%
WallTime test_perf_graphql_style_pydantic_v2 576.8 ms 779.8 ms -26.03%
WallTime test_perf_complex_refs 1.4 s 1.9 s -25.89%
WallTime test_perf_large_models_pydantic_v2 2.6 s 3.5 s -25.78%
WallTime test_perf_duplicate_names 757.7 ms 1,010.4 ms -25.01%
WallTime test_perf_large_models_pydantic_v2_noformat 634.9 ms 844.1 ms -24.78%
WallTime test_perf_openapi_large 2.2 s 2.9 s -24.22%
WallTime test_perf_stripe_style_pydantic_v2 1.5 s 1.9 s -24.05%
WallTime test_perf_kubernetes_style_pydantic_v2 1.9 s 2.5 s -23.43%
WallTime test_perf_aws_style_openapi_pydantic_v2 1.4 s 1.9 s -23.16%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing agent/skip-unused-formatter (1a0087d) with main (01303c3)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (01303c3) to head (1a0087d).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #3599   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          164       164           
  Lines        35325     35367   +42     
  Branches      4078      4079    +1     
=========================================
+ Hits         35325     35367   +42     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@koxudaxi koxudaxi merged commit 7e8b04e into main Jul 11, 2026
61 of 62 checks passed
@koxudaxi koxudaxi deleted the agent/skip-unused-formatter branch July 11, 2026 04:43
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: PR #3599 ("Skip unused formatter construction") is an internal performance optimization. In parse(), it skips building a code formatter only when self.formatters is an empty list AND there is no custom formatter AND _build_code_formatter has not been overridden on the instance or a subclass. In that specific case, building a CodeFormatter with an empty formatter list applies no transformations, so skipping it produces byte-identical generated output — the change avoids importing the formatter runtime (verified by the new test asserting imported_format is false). All override/escape-hatch paths (custom formatters, subclass overrides, instance-injected builders) are explicitly preserved and covered by new tests. No CLI options, API parameters, classes, enum values, or functions were removed (deleted lines are just the reformatted if-block). No default values or behavior changed for existing users. Therefore there are no breaking changes.


This analysis was performed by Claude Code Action

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant