Skip to content

Avoid copying entire mappings during type inference - #7057

Merged
FarhanAliRaza merged 3 commits into
mainfrom
codex/perf-bounded-mapping-inference
Nov 10, 2026
Merged

FarhanAliRaza merged 3 commits into
mainfrom
codex/perf-bounded-mapping-inference

Conversation

@Alek99

@Alek99 Alek99 commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Mapping type inference samples only 100 keys and values, but currently materializes every key and value before taking that sample. Use bounded iteration so inference keeps the same sample and resulting types without copying or retrieving the rest of a large mapping.

On a local CPython 3.14.5 / Apple M5 Pro benchmark, inference for a one-million-entry dict fell from 5.62 ms to 0.026 ms, with peak traced temporary allocation falling from 8 MB to 360 B. This measures the inference helper, not whole-app compilation. Added a CodSpeed benchmark across mapping sizes and regressions covering empty mappings, the exact sample boundary, and custom Mapping iteration/value access. The bounded-iteration regression fails on the unchanged base.

Validation:

  • Full unit suite: 8,303 passed, 18 skipped; 75.95% coverage.
  • Focused Var tests and new benchmark: 260 passed.
  • Repository-wide Ruff check and format check passed.
  • pyright reflex tests and changed-file type checks passed.

Independent of the other performance changes; based directly on main.

Review in cubic

@greptile-apps

greptile-apps Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

figure_out_type now samples mappings without first copying every key and value.

  • Mapping type inference reads only the first 100 keys and values.

No actionable issues were found. Tests were inspected, not run.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into codex/perf-boun..." · Reviewed by Greptile

@codspeed

codspeed Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 0.44%

2 warnings

⚠️ 19 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 2 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

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 146 untouched benchmarks
🆕 3 new benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_state_collection_assignment[1000] 11.4 ms 12.1 ms -5.05%
⚡ test_process_event_burst_independent_tokens[1] 2.8 ms 2.7 ms +4.39%
🆕 test_mapping_type_inference[100] N/A 1.4 ms N/A
🆕 test_mapping_type_inference[10000] N/A 1.4 ms N/A
🆕 test_mapping_type_inference[100000] N/A 1.4 ms N/A

Tip

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


Comparing codex/perf-bounded-mapping-inference (bbc1920) with main (982a6fb)

Open in CodSpeed

@masenf masenf added the perf Performance-improving changes label Sep 29, 2026
@FarhanAliRaza
FarhanAliRaza marked this pull request as ready for review November 9, 2026 12:09
@FarhanAliRaza
FarhanAliRaza requested a review from a team as a code owner November 9, 2026 12:09

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Turn on auto-fix | Re-trigger cubic

@FarhanAliRaza FarhanAliRaza added the on deck PRs lined up to review / merge next label Nov 9, 2026
@FarhanAliRaza
FarhanAliRaza merged commit 0d14360 into main Nov 10, 2026
167 of 168 checks passed
@FarhanAliRaza
FarhanAliRaza deleted the codex/perf-bounded-mapping-inference branch November 10, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

on deck PRs lined up to review / merge next perf Performance-improving changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants