Avoid copying entire mappings during type inference - #7057
Conversation
Greptile SummaryThis PR bounds mapping type inference to the first 100 keys and values without materializing complete mapping views.
Confidence Score: 5/5The PR appears safe to merge, with bounded iteration preserving the established type-inference sample for supported mappings. No actionable correctness, security, integration, or repository-rule issues remain; the implementation preserves first-100 sampling semantics and the tests cover the changed boundary behavior.
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/vars/base.py | Preserves the existing 100-item inference sample while avoiding work and allocation proportional to the entire mapping. |
| tests/units/reflex_base/vars/test_base.py | Verifies inferred types, exact sample boundaries, empty mappings, and bounded custom-mapping iteration and value access. |
| tests/benchmarks/test_type_inference.py | Adds a correctly integrated CodSpeed benchmark that measures inference independently of mapping construction. |
| packages/reflex-base/news/+bounded-mapping-inference.performance.md | Documents the downstream compilation-performance improvement in the package news format. |
Reviews (1): Last reviewed commit: "perf: bound mapping type inference to th..." | Re-trigger Greptile
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
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:
pyright reflex testsand changed-file type checks passed.Independent of the other performance changes; based directly on main.