ruff
d1da20cd - [ty] Use control flow checkpoints for statement calls (#30561)

Commit
4 hours ago
[ty] Use control flow checkpoints for statement calls (#30561) ## Summary When a generated UI method calls hundreds of setters, ty walks back through earlier calls to check whether any of them would prevent execution from reaching the current statement. We cache an intermediate result every 256 calls. Between checkpoints we can walk the same calls many times, doing a binary search at each step to see whether we've reached a checkpoint. We now select checkpoints for calls using the same rule we use for other control flow. After walking eight predicates, we look for a checkpoint based on the predicate ID. Nearby statements can reuse a cached result after a shorter walk, and we can drop the search through the list of calls. The closer spacing can retain more Salsa memos in long methods. Cold checks of Shuidi’s generated PyQt6 form used 16.12% fewer instructions. Checking all 89 Python files in Nugget used 7.60–7.76% fewer instructions. [Shuidi revision](https://github.com/MAOGE555/shuidi/blob/6de90e8b9a939c9e57cb2d4f2f2a965668f772f8/new.py) · [Nugget revision](https://github.com/leminlimez/Nugget/tree/26e0c50ec114ca3a4ff6ab2fb4ae309abfd39fa1) Median paired peak RSS rose by 742 KiB on Shuidi. On Nugget the median increase of 1,014 KiB was within the variation between baseline runs. | Project | [Base instructions](https://github.com/astral-sh/ruff/commit/248231e9936ecc0e44ecd3a69bc07899736e4e23) | [PR instructions](https://github.com/astral-sh/ruff/commit/ca233b092f1897fbfd658ced1be292c9a38e293d) | Change | Paired range | | --- | ---: | ---: | ---: | ---: | | [Black](https://github.com/psf/black/tree/55996d1fb8342725c8a19b6023cd9439c3c1d6f7) | 3,179,208,188.5 | 3,160,468,835.5 | -0.59% | -0.71% to -0.47% | | [discord.py](https://github.com/Rapptz/discord.py/tree/65232c38702be5844cf2ce865a4777eb1928b5d0) (inconclusive) | 8,234,941,180 | 8,248,831,934 | +0.13% | -0.02% to +0.17% | | [Home Assistant](https://github.com/home-assistant/core/tree/c19ae285ede74cd64c3045a3a4aa43290c224f1b) (inconclusive) | 160,010,941,358 | 160,033,050,064 | +0.01% | 0.00% to +0.02% | | [isort](https://github.com/pycqa/isort/tree/a514c71ed86c2216d0040c7d60e302ed76a4f7ab) | 1,841,091,500 | 1,837,145,491 | -0.21% | -0.22% to -0.21% | | [Jinja](https://github.com/pallets/jinja/tree/5ef70112a1ff19c05324ff889dd30405b1002044) (inconclusive) | 1,930,535,516.5 | 1,921,623,158 | -0.46% | -0.87% to -0.06% | | [pandas](https://github.com/pandas-dev/pandas/tree/a0225b65720018f4654390bb16d254daa6ee5e54) (inconclusive) | 30,072,961,014.5 | 30,071,468,706 | 0.00% | -0.03% to +0.02% | | [pandas-stubs](https://github.com/pandas-dev/pandas-stubs/tree/8dd6d91b1c05b26e30f7ddbe3dc3d4042a92bdd6) (inconclusive) | 2,923,102,449 | 2,931,714,627 | +0.29% | 0.00% to +0.42% | | [Prefect](https://github.com/PrefectHQ/prefect/tree/a9452ac21852755311913cb27887b083b5007c03) | 4,896,852,662.5 | 4,894,400,733 | -0.05% | -0.07% to -0.03% | | [PyTorch](https://github.com/pytorch/pytorch/tree/ab92945cea42e47ae398aead69af0872d340ea0f) | 98,352,722,060.5 | 97,951,489,525 | -0.41% | -0.43% to -0.38% | | [HTTPX](https://github.com/encode/httpx/tree/b5addb64f0161ff6bfe94c124ef76f6a1fba5254) (inconclusive) | 1,665,191,727 | 1,665,699,910 | 0.00% | -0.02% to +0.05% | | [NumPy](https://github.com/numpy/numpy/tree/f9f1772ce010001208475f751d19253469788410) (inconclusive) | 8,532,304,774 | 8,508,863,575.5 | -0.27% | -0.30% to -0.25% | | [FastAPI](https://github.com/fastapi/fastapi/tree/7a0a3f0b286c6c865cf4398ea0e957a87b8bffa4) (inconclusive) | 2,965,330,722.5 | 2,960,677,073.5 | -0.16% | -0.29% to -0.03% | | [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy/tree/10f4d1e2d706a7722ca78e79ce05b00333a7aa5b) (inconclusive) | 21,783,704,471 | 21,796,835,567.5 | +0.06% | -0.06% to +0.18% | | [Rich](https://github.com/Textualize/rich/tree/9d8f9a372cc5916fd4781fec207ced7ddac2f08f) (inconclusive) | 2,711,695,060.5 | 2,712,229,180.5 | +0.02% | -0.29% to +0.33% | | [Django](https://github.com/django/django/tree/b501b8493f31cf8cba31211d59b3b78642b8cb02) (inconclusive) | 13,995,374,688.5 | 13,990,397,766 | -0.04% | -0.11% to +0.04% | | [SymPy](https://github.com/sympy/sympy/tree/85d3998a4517ffbc8a9709b8efa769bb417c174a) (inconclusive) | 46,802,092,756.5 | 46,798,119,486.5 | -0.01% | -0.02% to +0.01% | | [OpenAI Python SDK](https://github.com/openai/openai-python/tree/f6e8480f9a5b2a4d02b17a1da54a1e57964bc312) | 15,977,459,855 | 15,987,345,132 | +0.07% | +0.06% to +0.10% | | [pytest](https://github.com/pytest-dev/pytest/tree/8b005ed7f972987033ec34dc1e68b0635fb8142b) | 8,824,268,687 | 8,832,404,265 | +0.07% | +0.07% to +0.25% | | [aiohttp](https://github.com/aio-libs/aiohttp/tree/fe099491d275ef2c21bf683e024e34d51ac05d43) (inconclusive) | 4,150,396,345.5 | 4,143,422,104.5 | -0.17% | -0.28% to -0.06% | | [Ansible](https://github.com/ansible/ansible/tree/b4b2b1e82a535d27f902a71fc8396c3af138fca2) | 14,571,156,422.5 | 14,507,603,093.5 | -0.44% | -0.44% to -0.43% | | [botocore](https://github.com/boto/botocore/tree/e250abbe956da791c16086575e6ddb1f2da81a78) (inconclusive) | 3,001,834,506 | 3,003,583,249 | +0.06% | -0.06% to +0.17% | | [Celery](https://github.com/celery/celery/tree/9c2f238334331db43f15956f131235fd3bb70fd1) (inconclusive) | 4,828,355,423.5 | 4,826,417,677 | -0.04% | -0.09% to +0.01% | | [Dask](https://github.com/dask/dask/tree/249a51a1db4261791b93b4ce04e67341729939c3) (inconclusive) | 35,978,090,519 | 35,948,401,773 | -0.08% | -0.13% to -0.03% | | [NetworkX](https://github.com/networkx/networkx/tree/6855cd586982cc2e4710b8eb87251ccf56674bf1) (inconclusive) | 16,468,944,617.5 | 16,445,025,380 | -0.15% | -0.22% to -0.08% | | [Pydantic](https://github.com/pydantic/pydantic/tree/560f0f96a37d6913afdfddb2de22030ef08e68c3) | 13,821,617,408 | 13,840,973,032 | +0.14% | +0.12% to +0.17% | | [scikit-learn](https://github.com/scikit-learn/scikit-learn/tree/ee56c8b5d809dc7b970a140ed501269b63c69cf8) (inconclusive) | 75,190,375,068 | 75,148,405,537.5 | -0.06% | -0.14% to +0.03% | | [Scrapy](https://github.com/scrapy/scrapy/tree/e63a574c767d7a9438c21db158f605f1c44c6e6a) (inconclusive) | 8,980,074,016.5 | 8,973,542,688.5 | -0.07% | -0.13% to -0.01% | | [Transformers](https://github.com/huggingface/transformers/tree/3a134bc37f7c22c801b618e289b0255425f22647) (inconclusive) | 105,060,132,657.5 | 105,002,927,918 | -0.05% | -0.08% to -0.03% | --------- Co-authored-by: Charlie Marsh <charliemarsh@openai.com>
Author
Parents
Loading