Skip to content

Skip unread Pydantic floor work and the lockfile path resolution - #6740

Merged
Koudai Aono (koxudaxi) merged 2 commits into
s43-protocolsfrom
perf-floor-lock
Nov 12, 2026
Merged

Koudai Aono (koxudaxi) merged 2 commits into
s43-protocolsfrom
perf-floor-lock

Conversation

@koxudaxi

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

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved remote lockfile handling so lockfile conflicts are checked against the selected lockfile, and locks are opened only when applicable.
    • Corrected compatibility checks for byte-pattern constraints, including when no explicit Pydantic target version is configured.
    • Avoided applying byte-pattern compatibility checks to fields that do not constrain only bytes.

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The remote lock flow now selects an active plan for conflict checks and lock opening. Pydantic checks now limit bytes-pattern inspection to bytes-only fields and collect Pydantic constructs only when a target version is configured.

Changes: Remote Lock Plan Selection

Layer / File(s) Summary
Select an active remote lock plan
src/datamodel_code_generator/_lock_plan.py
Lockfile path selection is centralized. Active plan selection returns no plan when neither lock mode is enabled and the lexical lockfile is not a file.
Resolve and open the remote lock
src/datamodel_code_generator/__init__.py
The generation lock resolver uses the active plan’s canonical path for conflict checks and opens a lock when a plan exists.

Pydantic Pattern and Target-Version Checks

Layer / File(s) Summary
Check bytes patterns and collect Pydantic constructs
src/datamodel_code_generator/model/pydantic_v2/base_model.py, src/datamodel_code_generator/parser/_passes/imports.py
The bytes-pattern check inspects only bytes-only fields. The floor pass collects constructs only when a target version is set and continues to collect refused patterns regardless of target version.

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

Change: Refactor

Merge Risk: Minimal · up to 66517

This change skips unneeded Pydantic floor work and lockfile path resolution as a performance optimization. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names two changes that the changeset makes: skipping Pydantic floor work when no target version is set, and skipping lockfile path resolution when no lock policy applies. The raw summary con…
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: Title check

Explanation

The title names two changes that the changeset makes: skipping Pydantic floor work when no target version is set, and skipping lockfile path resolution when no lock policy applies. The raw summary confirms both areas: imports.py gates construct collection on an explicit target, and _lock_plan.py adds active_remote_lock_plan, which returns None when no lock mode is active. The title is specific and accurate, though it is a little jargon-heavy for readers outside the code.

Finishing Touches

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 410b728 and 66517b3.

Files selected for processing: 4

  • src/datamodel_code_generator/__init__.py
  • src/datamodel_code_generator/_lock_plan.py
  • src/datamodel_code_generator/model/pydantic_v2/base_model.py
  • src/datamodel_code_generator/parser/_passes/imports.py

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

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

chatgpt-codex-connector Bot commented Nov 11, 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-11T23:11:19.690034Z 66517b3 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

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Nov 11, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 47.69%

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 regressed benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_client_calls[sync] 19.8 ms 43.9 ms -54.98%
❌ test_perf_client_calls[async] 22.2 ms 48.9 ms -54.63%
❌ test_perf_load_pyproject_config[config-multiple] 119.4 µs 262.9 µs -54.59%
❌ test_perf_load_pyproject_config[mapping-multiple] 120.9 µs 262.1 µs -53.86%
❌ test_perf_load_pyproject_config[mapping-None] 115 µs 248.3 µs -53.7%
❌ test_perf_load_pyproject_config[config-None] 112.6 µs 242.9 µs -53.64%
❌ test_perf_load_yaml_openapi_large 18.6 ms 39.1 ms -52.33%
❌ test_perf_pydantic_field_name_resolution 1.3 ms 2.8 ms -52.19%
❌ test_perf_simple_msgspec_unset_field_rendering 288.8 ms 592.4 ms -51.25%
❌ test_perf_unique_items_runtime_scalar_validation 1.6 ms 3.1 ms -50.45%
❌ test_perf_false_reference_validation 221.6 ms 447.1 ms -50.44%
❌ test_perf_target_render[client-small] 21 ms 42.1 ms -50.1%
❌ test_perf_large_models_typed_dict[total-false-requiredness] 723.4 ms 1,447.7 ms -50.03%
❌ test_perf_mapped_reference_users 503.7 ms 1,005.4 ms -49.89%
❌ test_perf_complex_refs 1.2 s 2.5 s -49.68%
❌ test_perf_scalar_root_collapsed_builtin 120.7 ms 239.6 ms -49.63%
❌ test_perf_large_models_typed_dict[legacy-requiredness] 731.3 ms 1,449.1 ms -49.54%
❌ test_perf_duplicate_names 600.2 ms 1,189 ms -49.52%
❌ test_perf_unique_items_nested_model_validation 1.6 ms 3.2 ms -49.39%
❌ test_perf_large_models_dataclass_builtin 845.8 ms 1,662.9 ms -49.14%
... ... ... ... ...

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

Tip

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


Comparing perf-floor-lock (66517b3) with s43-protocols (410b728)

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. ↩

@koxudaxi
Koudai Aono (koxudaxi) merged commit 94a47cf into main Nov 12, 2026
116 of 117 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the perf-floor-lock branch November 12, 2026 01:01
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: The PR is an internal performance refactor that keeps behaviour the same. In init.py the remote lock resolution now calls a new private helper, active_remote_lock_plan in _lock_plan.py. It returns None when neither update_lock nor locked is set and no lockfile exists at the lexical path, and otherwise returns the same plan as remote_lock_plan, so the lockfile and the active check give the same results as before. The literal path computation was moved into a private _literal_lockfile helper with the same expression. In the pydantic_v2 DataModelField pattern check, the bytes-only check now runs first so the method can return early, which gives the same boolean result. In record_pydantic_floor, Pydantic constructs are now collected only when a target Pydantic version is set, and they were only used in that case before, so the recorded floor and refused fields are unchanged. No public CLI options, Python API names, templates, defaults or error handling changed. The behaviour diff gate lists only both-fail cells, with no accepted or violation cells, so default generated output is identical to release 0.94.0.


This analysis was produced by the release draft workflow

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.95.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