Skip to content

Store mapping pattern entries and captures in source order - #29889

Draft
MichaReiser wants to merge 1 commit into
micha/boxed-python-dict-itemsfrom
micha/boxed-mapping-pattern-items
Draft

MichaReiser wants to merge 1 commit into
micha/boxed-python-dict-itemsfrom
micha/boxed-mapping-pattern-items

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Store each mapping-pattern key with its pattern and keep **name captures in the same sequence. A source-order visitor can then read the sequence directly. For recovered syntax such as case {**first, "x": value, **last}:, the AST retains both captures where they appeared. Consumers that ask for the rest capture continue to get the last one.

The parser, formatter, code generator, and ty read this representation from the boxed AST. On a file with 1,024 mapping patterns, each with two entries and a capture, the change reduced parsing from 10,312,958 to 10,156,245 instructions (−1.52%) and the source-order walk from 415,019 to 351,531 (−15.30%). Retained syntax fell from 829,880 to 813,496 bytes (−1.97%).

These measurements predate the comparison optimizations in #30033.

Instructions relative to the boxed parent Change
Parse five standard fixtures, pooled −0.0005%
Ruff lint, CPython +0.36%
Ruff format check, CPython, concise output +0.13%
ty check, standard library +0.11%
ty check, Pygments +0.12%
ty check, Jinja2 +0.08%

The five standard parser fixtures contain no mapping patterns. Their retained syntax size was unchanged, and the three paired parser measurements ranged from −0.04% to +0.03%. The CLI comparisons produced identical output.

Test Plan

Parser and source-order tests cover valid mappings, misplaced captures, and repeated captures. The updated parser snapshots preserve the existing source ranges and diagnostics. The formatter fixtures, linter tests, ty IDE tests, and ty mdtests passed.

@MichaReiser MichaReiser added internal An internal refactor or improvement (not for changelogs) parser Related to the parser labels Nov 1, 2026
@MichaReiser
MichaReiser added this pull request to stack #29884 November 1, 2026 20:12
@astral-automations-bot

astral-automations-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 98.60%. The percentage of expected errors that received a diagnostic held steady at 98.86%. The number of fully passing files held steady at 137/146.

Results for 3c2225d · Workflow run

@astral-automations-bot

astral-automations-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Memory usage report

Memory usage unchanged ✅


Results for 3c2225d · Workflow run

@astral-automations-bot

astral-automations-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff · Timing results


Results for 3c2225d · Workflow run

@astral-automations-bot

astral-automations-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)

astropy/astropy (error)

ruff format --preview

warning: Detected debug build without --no-cache.
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)
error: Encountered error: No such file or directory (os error 2)

Linter (stable) · Linter (preview) · Formatter (stable) · Formatter (preview)


Results for 3c2225d · Workflow run

@MichaReiser
MichaReiser removed this pull request from stack #29884 November 1, 2026 22:35
@MichaReiser
MichaReiser added this pull request to stack #29893 November 1, 2026 22:36
@MichaReiser
MichaReiser removed this pull request from stack #29893 November 2, 2026 10:51
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 0363709 to 8bf7e54 Compare November 2, 2026 10:52
@MichaReiser
MichaReiser added this pull request to stack #29900 November 2, 2026 10:52
@codspeed

codspeed Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 294 untouched benchmarks
⏩ 14 skipped benchmarks1


Comparing micha/boxed-mapping-pattern-items (3c2225d) with micha/boxed-python-dict-items (23ae436)

Open in CodSpeed

Footnotes

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

@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 8bf7e54 to 1b416e6 Compare November 2, 2026 11:30
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 1b416e6 to ae3af64 Compare November 2, 2026 13:48
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from ae3af64 to 1f4ded9 Compare November 2, 2026 13:56
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 1f4ded9 to 44451d2 Compare November 2, 2026 14:05
@MichaReiser
MichaReiser removed this pull request from stack #29900 November 2, 2026 15:39
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 19fc665 to c659764 Compare November 2, 2026 16:32
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from c659764 to fa3337b Compare November 2, 2026 17:27
@MichaReiser
MichaReiser removed this pull request from stack #29912 November 2, 2026 18:36
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from fa3337b to 503f8a4 Compare November 2, 2026 18:37
@MichaReiser
MichaReiser added this pull request to stack #29918 November 2, 2026 18:38
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 503f8a4 to 3388804 Compare November 3, 2026 15:33
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 3388804 to 48b7491 Compare November 3, 2026 16:14
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 48b7491 to 475a836 Compare November 4, 2026 11:59
@MichaReiser
MichaReiser removed this pull request from stack #29918 November 4, 2026 12:02
@MichaReiser
MichaReiser added this pull request to stack #30034 November 4, 2026 12:03
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 475a836 to 0f8d2da Compare November 4, 2026 13:30
@MichaReiser
MichaReiser removed this pull request from stack #30034 November 4, 2026 13:31
@MichaReiser
MichaReiser added this pull request to stack #30037 November 4, 2026 13:31
@MichaReiser
MichaReiser force-pushed the micha/boxed-mapping-pattern-items branch from 0f8d2da to 3c2225d Compare November 4, 2026 17:57

This branch was previously deployed

1 inactive deployment
automations — 3c2225d1 Deployed Nov 4, 2026 by MichaReiser via security-review / security review #97197
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement (not for changelogs) parser Related to the parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant