Skip to content

Remember logical line layouts in the builtin formatter - #6697

Merged
Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
bspeed-cache
Nov 11, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
mainfrom
bspeed-cache

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Performance
    • Repeated formatting of logical lines may now complete more quickly, while formatted output remains available in the expected list format. Custom formatting behavior is unchanged.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The formatter now caches logical-line layouts for the default restore function. It returns formatted lines as a list and uses the uncached layout function for custom restore functions.

Changes: Formatter layout cache

Layer / File(s) Summary
Cache layout results
src/datamodel_code_generator/_builtin_line_split.py
format_logical_line uses a cached layout for the default restore function and the direct layout function for custom restore functions. The layout function returns a tuple, and format_logical_line returns a list.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Possibly related issues

Possibly related PRs

Suggested labels: breaking-change-analyzed

Merge Risk: Minimal · up to b3b39

The formatter now caches default logical-line layouts. No merge-blocking behavior change was established.

Pre-merge checks: Passed 5

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: caching logical line layouts in the builtin formatter.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f478c79 and b3b3946.

Files selected for processing: 1

  • src/datamodel_code_generator/_builtin_line_split.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 10, 2026 20:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T20:26:51.109679Z b3b3946 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 10, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 52.45%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 53 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 53 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_target_render[client-small] 62.5 ms 28.7 ms ×2.2
⚡ test_perf_target_render[fastapi-small] 34.4 ms 17.9 ms +92.52%
⚡ test_perf_simple_msgspec_unset_field_rendering 596.1 ms 334.1 ms +78.45%
⚡ test_perf_load_pyproject_config[mapping-multiple] 265.4 µs 152.7 µs +73.84%
⚡ test_perf_load_pyproject_config[mapping-None] 247.2 µs 142.2 µs +73.84%
⚡ test_perf_load_pyproject_config[config-multiple] 264.1 µs 153 µs +72.64%
⚡ test_perf_load_pyproject_config[config-None] 240 µs 140.2 µs +71.17%
⚡ test_perf_client_calls[async] 48.7 ms 28.5 ms +70.99%
⚡ test_perf_client_calls[sync] 43.5 ms 25.7 ms +69.41%
⚡ test_perf_scalar_root_collapsed_builtin 247.5 ms 153.1 ms +61.66%
⚡ test_perf_ordinary_array_constraint_generation 2.7 s 1.7 s +58.16%
⚡ test_perf_large_models_dataclass_builtin 1.7 s 1 s +57.86%
⚡ test_perf_large_models_typed_dict[total-false-requiredness] 1,385.7 ms 877.9 ms +57.85%
⚡ test_perf_large_models_msgspec 2.4 s 1.5 s +56.96%
⚡ test_perf_target_render[fastapi-large] 10.4 s 6.7 s +55.69%
⚡ test_perf_local_reference_file_resolution 167.8 ms 108 ms +55.35%
⚡ test_perf_inherited_required_fields[required-derived-first] 1,015.8 ms 656.8 ms +54.66%
⚡ test_perf_large_models_single_module_stdout 2 s 1.3 s +54.58%
⚡ test_perf_graphql_style_pydantic_v2 1,000.9 ms 650.2 ms +53.94%
⚡ test_perf_large_models_pydantic_v2 4.2 s 2.7 s +53.67%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing bspeed-cache (b3b3946) with main (f478c79)

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 Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koxudaxi
Koudai Aono (koxudaxi) merged commit 3395b7f into main Nov 11, 2026
117 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the bspeed-cache branch November 11, 2026 06:52
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR only changes the private module _builtin_line_split.py to speed up formatting: format_logical_line now hands its work to a new private helper, _logical_line_layout, whose results are stored in an lru_cache of 1024 entries when restore is the default str. The cached arguments are strings, ints and bools, and the same input always gives the same layout, so caching cannot change results. format_logical_line still returns the same rows and list shape, or None. The only removed lines are the old functools import and the old return statement. No public option, CLI flag, template, default value or public Python name changed. Every behaviour diff cell is both-fail, with none accepted or violation, so default output is unchanged.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.93.0

This PR is now available in the latest release. See the release notes for details.

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