Skip to content

[red-knot] Improve property test performance by cloning db instead of holding MutexGuard #16823

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

cake-monotone
Copy link
Contributor

Summary

This PR brings an optimization.

  • get_cached_db no longer returns a MutexGuard; instead, it returns a cloned database.

get_cached_db

Previously, the MutexGuard was held inside the property test function (defined in the macro), which prevented multiple property tests from running in parallel. More specifically, the program could only test one random test case at a time, which likely caused a significant bottleneck.

On my local machine, running:

QUICKCHECK_TESTS=100000 cargo test --release -p red_knot_python_semantic -- --ignored stable

showed about a 75% speedup (from ~60s to ~15s).

@cake-monotone cake-monotone changed the title [red-knot] Make proprety tests faster [red-knot] Improve property test performance by cloning db instead of holding MutexGuard Mar 18, 2025
Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Nice find.

@MichaReiser MichaReiser added testing Related to testing Ruff itself ty Multi-file analysis & type inference labels Mar 18, 2025
@MichaReiser MichaReiser merged commit 3e2cf5d into astral-sh:main Mar 18, 2025
23 checks passed
@cake-monotone cake-monotone deleted the cake/make-property-tests-faster branch March 18, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to testing Ruff itself ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants