Skip to content

[ty] Avoid merging snapshots if equivalent#24682

Closed
charliermarsh wants to merge 1 commit intomainfrom
charlie/fix2-builder-shortcircuit
Closed

[ty] Avoid merging snapshots if equivalent#24682
charliermarsh wants to merge 1 commit intomainfrom
charlie/fix2-builder-shortcircuit

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Apr 16, 2026

Summary

The idea here is: most of the time, most bindings don't change in an if block or equivalent. For example, given:

def f(x: int, y: str, z: list[int]) -> None:
    a = 1
    b = "hello"
    c = []
    if x > 0:
        a = 2

a changed, but all the other symbols were unchanged, so we can avoid running the full merge for the PlaceState for all other symbols.

This doesn't show up in any of our standard benchmarks, but it's a pretty simple optimization and shows a 38% speedup for an example like:

class BigClass:
    def __init__(self, data: dict[str, int]) -> None:
        if "field_0" in data: self.field_0 = data["field_0"]
        else: self.field_0 = 0
        ...  # 2000 fields

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Apr 16, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 16, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 89.34%. The percentage of expected errors that received a diagnostic held steady at 85.30%. The number of fully passing files held steady at 87/134.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 16, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 16, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh added the performance Potential performance improvement label Apr 17, 2026
@charliermarsh charliermarsh force-pushed the charlie/fix2-builder-shortcircuit branch from 3d431df to 9f7668b Compare May 2, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Potential performance improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant