Use worksteal distribution strategy with pytest-xdist - #1916
Conversation
Pytest-xdist has options to [control distribution of jobs across workers](https://pytest-xdist.readthedocs.io/en/stable/distribution.html). Experimenting with different choices led to the discovery that the `worksteal` strategy speeds up execution of the Qualtran test suite. It appears to have no negative consequences. Running this without the thread-limiting PR (), using `--dist worksteal` affords a roughly 12% speedup for the quick tests, which is a modest amount but still something. Rough average timing results: `pytest-quick`: * Before: ~185 seconds * After: ~165 seconds `pytest-full`: * Before: ~970 seconds * After: ~915 seconds
--dist worksteal to Pytest optionsworksteal distribution strategy with pytest-xdist
There was a problem hiding this comment.
Code Review
The pull request refactors pytest_configure in qualtran/conftest.py by extracting thread-limiting logic into _config_set_thread_limits and introducing _config_set_xdist_worksteal to set --dist worksteal as the default distribution mode when using pytest-xdist. It also adds corresponding unit tests in qualtran/conftest_test.py. Feedback highlights two issues in _config_set_xdist_worksteal: it incorrectly overrides the distribution mode during sequential runs (when parallel execution is disabled) and fails to respect --dist configurations defined in addopts within configuration files. A code suggestion is provided to address these issues and safely handle cases where pytest-xdist is not installed.
This makes it take account of possible user settings.
|
/gemini review |
|
This is a great optimization! Using |
Pytest-xdist has options to control distribution of jobs across workers. Experimenting with different choices led to the discovery that the
workstealstrategy speeds up execution of the Qualtran test suite. It appears to have no negative consequences. Using--dist workstealaffords a roughly 20–40% speedup for the quick test and 6% for the full tests.Rough average timing results:
pytest-quick:pytest-full: