Skip to content

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Aug 11, 2025

Summary

Fixes astral-sh/ty#968

This reduces the wall time for a large project from ~24s to ~19s. I plan to do another perf recording to verify that the lock congestion is entirely gone but I first need to walk the dog :)

See inline comment for more details.

Test Plan

cargo nextest

@MichaReiser MichaReiser added the performance Potential performance improvement label Aug 11, 2025
@MichaReiser MichaReiser requested a review from carljm as a code owner August 11, 2025 16:29
@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Aug 11, 2025
@MichaReiser MichaReiser added performance Potential performance improvement ty Multi-file analysis & type inference labels Aug 11, 2025
Copy link
Contributor

github-actions bot commented Aug 11, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Copy link

codspeed-hq bot commented Aug 11, 2025

CodSpeed WallTime Performance Report

Merging #19867 will not alter performance

Comparing micha/short-circuit-into-callable (c353acd) with main (f3f4db7)

Summary

✅ 8 untouched benchmarks

@MichaReiser
Copy link
Member Author

MichaReiser commented Aug 11, 2025

Nice, this is even a win for non concurrent runs. All credit goes to @carljm for the much better fix than what I came up with

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Very nice!!

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

Perf results look amazing! Hopefully they persist once we get the logic right 😆 (I expect they will)

// doesn't help much.
// See <https://github.com/astral-sh/ty/issues/968>.
if matches!(ty, Type::Dynamic(_)) {
return Truthiness::AlwaysTrue.negate_if(!predicate.is_positive);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I gave you the wrong info here, I had the sense of this constraint reversed in my head. This needs to return Truthiness::AlwaysFalse, not Truthiness::AlwaysTrue! I suspect the mypy-primer run is taking so long because there are now tons more bogus diagnostics 😆

The fact that no test failed on this change also suggests we need an explicit mdtest like this:

from typing import Never, Any

def f(func: Any) -> Never:
    func()

Where an invalid-return-type is expected (because the call to func() is not terminal). That test fails on this PR currently.

Suggested change
return Truthiness::AlwaysTrue.negate_if(!predicate.is_positive);
return Truthiness::AlwaysFalse.negate_if(!predicate.is_positive);

Copy link
Member Author

@MichaReiser MichaReiser Aug 11, 2025

Choose a reason for hiding this comment

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

Don't worry, it does. The most congested lock is now for IntersectionType:

image

And the wall clock time on the large project on my linux machine goes from 42s .. to 16s which is rather ridiculous

Copy link
Contributor

github-actions bot commented Aug 11, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@MichaReiser MichaReiser requested a review from carljm August 11, 2025 18:28
@MichaReiser
Copy link
Member Author

Okay, the single threaded benchmarks don't improve by that much anymore. But it's still a huge improvement for multi threaded workloads (with many cores... not what github actions provides)

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

Awesome!

@MichaReiser MichaReiser merged commit 2abd683 into main Aug 11, 2025
38 checks passed
@MichaReiser MichaReiser deleted the micha/short-circuit-into-callable branch August 11, 2025 19:58
dcreager added a commit that referenced this pull request Aug 12, 2025
* main:
  Don't cache files with diagnostics (#19869)
  [ty] support recursive type aliases (#19805)
  [ty] Remove unsafe `salsa::Update` implementations in `tuple.rs` (#19880)
  [ty] Function argument inlay hints (#19269)
  [ty] Remove Salsa interning for `TypedDictType` (#19879)
  Fix `lint.future-annotations` link (#19876)
  [ty] Reduce memory usage of `TupleSpec` and `TupleType` (#19872)
  [ty] Track heap usage of salsa structs (#19790)
  Update salsa to pull in tracked struct changes (#19843)
  [ty] simplify CycleDetector::visit signature (#19873)
  [ty] use interior mutability in type visitors (#19871)
  [ty] Fix tool name is None when no ty path is given in ty_benchmark (#19870)
  [ty] Remove `Type::Tuple` (#19669)
  [ty] Short circuit `ReachabilityConstraints::analyze_single` for dynamic types (#19867)
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.

Low CPU saturation
4 participants