Skip to content

Move render caches into per-parse store memos - #5157

Merged
Koudai Aono (koxudaxi) merged 1 commit into
peak-rss-guardfrom
gr12-render-memos
Oct 23, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
peak-rss-guardfrom
gr12-render-memos

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added a render-memo check that can detect stale generated values and report or flag discrepancies.
  • Bug Fixes

    • Updated memoized model and enum lookups to reflect changes made during parsing and rendering.
  • Refactor

    • Consolidated temporary rendering and model lookup caches into parse-scoped memoization.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between ab6ee94 and f805a47.

⛔ Files ignored due to path filters: 11
  • docs/llms-full.txt is excluded by none and included by none
  • tests/data/expected/main/main_general/enum_member_index_that_an_extension_makes_stale[report].report.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/main_general/enum_member_index_that_an_extension_makes_stale[report].txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/main_general/render_memo_that_an_extension_makes_stale[off].txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/main_general/render_memo_that_an_extension_makes_stale[report].report.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/main_general/render_memos_record_the_stale_values_legacy_rows_keep[dedup-keys].report.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/main/main_general/render_memos_record_the_stale_values_legacy_rows_keep[self-reference].report.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/generation_store_usage/checker_follows_aliases_through_rebinding_and_entries.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/generation_store_usage/checker_forgets_skipped_names_when_they_are_rebound.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/generation_store_usage/checker_reports_fact_presentation_and_cache_writes_in_parser_code.txt is excluded by !tests/data/**/*.txt and included by none
  • tests/data/expected/parser/generation_store_usage/checker_scans_model_hooks_helpers_and_caches.txt is excluded by !tests/data/**/*.txt and included by none
📒 Files selected for processing: 22
  • docs/architecture.md
  • scripts/generation_store_allowlist.toml
  • src/datamodel_code_generator/_checks.py
  • src/datamodel_code_generator/_model_keys.py
  • src/datamodel_code_generator/_parse_memo.py
  • src/datamodel_code_generator/model/_render_plan.py
  • src/datamodel_code_generator/model/base.py
  • src/datamodel_code_generator/model/enum.py
  • src/datamodel_code_generator/parser/_facts.py
  • src/datamodel_code_generator/parser/_holders.py
  • src/datamodel_code_generator/parser/_model_shapes.py
  • src/datamodel_code_generator/parser/_sites.py
  • src/datamodel_code_generator/parser/base.py
  • src/datamodel_code_generator/parser/generation.py
  • src/datamodel_code_generator/types.py
  • tests/conftest.py
  • tests/main/test_main_general.py
  • tests/main/test_main_general.refs
  • tests/model/test_base.py
  • tests/parser/test_base.py
  • tests/parser/test_generation.py
  • tests/parser/test_generation_store_usage.py
💤 Files with no reviewable changes: 2
  • src/datamodel_code_generator/parser/_facts.py
  • scripts/generation_store_allowlist.toml

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

📝 Walkthrough

The change introduces parse-scoped memo tables for derived model and rendering values. Parser and model code use the shared memo state for cache reads and invalidation. A new check area detects stale memo values, and tests cover its check, report, and off modes.

Changes: Parse-scoped memo behavior

Layer / File(s) Summary
Memo API and parse lifecycle
src/datamodel_code_generator/_model_keys.py, src/datamodel_code_generator/_parse_memo.py, src/datamodel_code_generator/parser/generation.py, src/datamodel_code_generator/parser/base.py, src/datamodel_code_generator/parser/_holders.py, src/datamodel_code_generator/parser/_sites.py
New memo tables store values by owner, epoch, and arguments. GenerationStore creates a ParseMemo, and Parser.parse binds it for the parse pipeline.
Model and rendering cache migration
src/datamodel_code_generator/model/*, src/datamodel_code_generator/types.py, src/datamodel_code_generator/parser/_facts.py, src/datamodel_code_generator/parser/_model_shapes.py, src/datamodel_code_generator/parser/base.py, scripts/generation_store_allowlist.toml
Model self-reference, nested-model constructor-field, deduplication, enum-index, and union-render values use memo tables instead of per-instance caches. Related invalidation and cache-tracking entries are updated.
Stale-memo checks and validation
src/datamodel_code_generator/_checks.py, tests/conftest.py, tests/main/test_main_general.py, tests/main/test_main_general.refs, tests/model/test_base.py, tests/parser/test_base.py, tests/parser/test_generation.py, tests/parser/test_generation_store_usage.py, docs/architecture.md
RENDER_MEMOS adds stale-value checking, including report-mode records for legacy rows. Tests cover stale values and invalidation, and the architecture documentation describes the memo lifecycle.

Priority: ⬇️ Low

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

Change: Refactor

Possibly related issues

Merge Risk: ⚪ Minimal · up to f805a

No concrete issue remains that should prevent merging after normal checks.

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 and concisely describes the main change: moving render caches into per-parse store memos.
Docstring Coverage Passed Docstring coverage is 89.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 89 functions across 18 files. (2 skipped: 2…
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 89.89% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 89 functions across 18 files. (2 skipped: 2 unsupported.)

✨ Finishing Touches: 💡 1
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T18:19:40.604677Z f805a47 PR opened
ℹ️ 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 Oct 22, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 29.4%

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

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

❌ 49 regressed benchmarks
✅ 1 untouched benchmark
⏩ 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] 23.9 ms 41.6 ms -42.44%
❌ test_perf_client_calls[async] 27.1 ms 46 ms -41%
❌ test_perf_load_pyproject_config[mapping-None] 229.9 µs 367.6 µs -37.46%
❌ test_perf_load_pyproject_config[mapping-multiple] 237 µs 373.2 µs -36.51%
❌ test_perf_load_pyproject_config[config-None] 227.8 µs 358.6 µs -36.47%
❌ test_perf_load_pyproject_config[config-multiple] 238.2 µs 374.5 µs -36.39%
❌ test_perf_recommend_options_full_kubernetes_style 13 s 20.3 s -36.04%
❌ test_perf_scalar_root_collapsed_builtin 140 ms 214.5 ms -34.76%
❌ test_perf_local_reference_file_resolution 104.6 ms 158.1 ms -33.83%
❌ test_perf_all_options_enabled 4.4 s 6.7 s -33.77%
❌ test_perf_simple_msgspec_unset_field_rendering 114.2 ms 169.7 ms -32.73%
❌ test_perf_deep_nested 4.1 s 5.9 s -31.02%
❌ test_perf_large_models_pydantic_v2 2.7 s 3.9 s -30.94%
❌ test_perf_inherited_required_fields[partial-base-first] 758.1 ms 1,097.5 ms -30.92%
❌ test_perf_openapi_large 2.4 s 3.4 s -30.61%
❌ test_perf_large_models_single_module_stdout 1.1 s 1.6 s -30.6%
❌ test_perf_kubernetes_style_pydantic_v2 2 s 2.9 s -30.6%
❌ test_perf_ordinary_array_constraint_generation 1.4 s 2 s -30.4%
❌ test_perf_inherited_required_fields[partial-derived-first] 809.8 ms 1,158.4 ms -30.09%
❌ test_perf_extreme_large_schema 11.8 s 16.9 s -30.05%
... ... ... ... ...

ℹ️ 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 gr12-render-memos (f805a47) with peak-rss-guard (ab6ee94)

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 Oct 22, 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 8ed0879 into main Oct 23, 2026
131 of 132 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the gr12-render-memos branch October 23, 2026 02:20
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor that moves values cached on mutable models, fields and data type nodes (the dedup key cache, the self reference cache, the nested model required constructor fields marker, the enum member indexes and the rendered union members) into a per-parse memo owned by the generation store, active while Parser.parse runs. Everything removed is private: underscore attributes, the _SEMANTIC_CACHE_KEYS class variable, internal fact and allowlist rows, and NodeKey and FieldKey moving between private modules. The _iter_union_member_type_hints helper now returns a list and the private _same_value helper no longer compares tuples element by element. Public methods such as get_dedup_key, self_reference, invalidate_render_caches, clear_imports_cache and invalidate_semantic_caches keep their signatures and now drop memo entries. No existing expected output changed, and the new tests show output matching version 0.86.0. The new DATAMODEL_CODE_GENERATOR_CHECK_RENDER_MEMOS debug check is opt-in through an environment variable. There are no template, CLI, default, Python version or error-reporting changes. The only user-visible effect is that values read outside a parse are recomputed each time instead of cached, which can cost speed but gives the same results, so nothing here is breaking.


This analysis was produced by the release draft workflow

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