Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

perf: return fromis_subtype early#19400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JukkaL merged 4 commits intopython:masterfromsterliakov:feature/st-issubtype-perf-2
Jul 16, 2025

Conversation

@sterliakov
Copy link
Collaborator

Our equality implementation is conservative: if two types compare equal, we know for sure they do indeed refer to the same type, and any type is subtype of itself. This saved 0.9% in my local benchmark run.

@ilevkivskyi
Copy link
Member

I guess this caused performance regression forcolours? Or maybe it is just a fluctuation, we will see now. In general I think this may cause performance regression for code with many subtype checks with negative outcome, most notably in overloads checking (which is likely whycolours is so slow in the first place).

@sterliakov
Copy link
CollaboratorAuthor

Let's see if the restart helps - I've seen this happening randomly elsewhere.

@sterliakov
Copy link
CollaboratorAuthor

sterliakov commentedJul 8, 2025
edited
Loading

Isolated benchmarks also look good:sterliakov/mypy-issues#110

This can have negative effect when almost all subtype checks are expected to fail, but the checkshould be fast enough to compensate for that. Looking at primer logs,all other projects I looked at (~20 instances from five shards) were checked faster with this patch, so this might be net positive anyway.

Some long-running examples:

/tmp/mypy_primer/mypy_new/venv/bin/mypy on core took 583.57s/tmp/mypy_primer/mypy_old/venv/bin/mypy on core took 608.09s/tmp/mypy_primer/mypy_new/venv/bin/mypy on rclip took 30.12s/tmp/mypy_primer/mypy_old/venv/bin/mypy on rclip took 31.93s/tmp/mypy_primer/mypy_new/venv/bin/mypy on svcs took 61.66s/tmp/mypy_primer/mypy_old/venv/bin/mypy on svcs took 63.76s/tmp/mypy_primer/mypy_new/venv/bin/mypy on arviz took 145.72s/tmp/mypy_primer/mypy_old/venv/bin/mypy on arviz took 148.53s

This is obviously not the best indicator, but at least something...

colour, however, seems to demonstrate negative impact:

/tmp/mypy_primer/mypy_old/venv/bin/mypy on colour took 3223.60s/tmp/mypy_primer/mypy_new/venv/bin/mypy on colour took 3298.71s

It's not clear whether any of those are reliable, because the run for#19388 shows significantly lower time with expected positive improvement, but is 3 minutes less for master branch:

/tmp/mypy_primer/mypy_new/venv/bin/mypy on colour took 3013.21s/tmp/mypy_primer/mypy_old/venv/bin/mypy on colour took 3095.46s

(failingjoin_artifacts has nothing to do with this PR, it's likely a github outage:https://github.com/python/mypy/actions/runs/16144405699/job/45564336755?pr=19400)

@sterliakov
Copy link
CollaboratorAuthor

And let's also note that primer runs interpreted mypy, and this equality should play well with mypyc. I'll try running perf_compare on colour today.

@github-actions

This comment has been minimized.

@sterliakov
Copy link
CollaboratorAuthor

In this run there's no colour regression:

/tmp/mypy_primer/mypy_new/venv/bin/mypy on colour took 2875.19s/tmp/mypy_primer/mypy_old/venv/bin/mypy on colour took 2939.26s

but "need type annotation" is mysterious.

@sterliakov
Copy link
CollaboratorAuthor

sterliakov commentedJul 10, 2025
edited
Loading

Okay, nothing mysterious, just a separate bug. Please ping me if you don't think this PR should ever be merged, I will extract the bugfix to a separate PR -def fn(x) -> bool anddef fn(x) -> TypeGuard[int] definitely should not compare equal.

This was fun to debug - I ended up withassert sorted(repr(left)) == sorted(repr(right)) in these early return branches to check that equality works as expected, and got a jaw-dropping moment when it actually failed.

And this does indeed improvecolour check time, the first run was apparently a glitch or artifact running checks concurrently, it became faster in its own shard. Compiled benchmark (with numpy and other relevant packages installed) shows -2.4% over 3 runs (each run takes ~4 min on my PC so I wasn't ready to wait longer).

@github-actions
Copy link
Contributor

According tomypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL
Copy link
Collaborator

I'll play around with this a little (might be a few days though). If this looks like a fairly reliable perf win, I think I'd lean towards merging. There may also be some easy ways to speed up type equality, making this even faster.

@sterliakov
Copy link
CollaboratorAuthor

Self-check benchmark is at steady -1% or so, and primer runs do not reveal any perf regressions (though they aren't reliable at all due to concurrent execution), so looks like this is beneficial overall.

Copy link
Collaborator

@JukkaLJukkaL left a comment

Choose a reason for hiding this comment

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

I don't think we've seen a confirmed regression caused by this, and this seems to generally be a nice win, so let's merge this.

@JukkaLJukkaL merged commitedd491f intopython:masterJul 16, 2025
20 checks passed
@JukkaL
Copy link
Collaborator

Our nightly benchmarks runner is showing a nice 1.7% performance improvement:https://github.com/mypyc/mypyc-benchmark-results/blob/master/reports/benchmarks/mypy_self_check.md (commitedd491f30aa6 in the table)

brianschubert and sterliakov reacted with hooray emoji

JukkaL pushed a commit that referenced this pull requestNov 18, 2025
Fixes#19996.This was unearthed by#19400 where `is_subtype(Partial<X>, Partial<X>)`started returning True - before that `binder.assign_type(expr,Partial<None>, Partial<None>)` just returned early. If I understandcorrectly, that is how Partial should be handled here: we do not want topush partials to the binder. I do not think we should add a special casefor that (both False and True make some sense for a partial type, I amnot convinced that either one is marginally better), so I just add anexplicit guard to skip adding partial types here.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JukkaLJukkaLJukkaL approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@sterliakov@ilevkivskyi@JukkaL

[8]ページ先頭

©2009-2025 Movatter.jp