[8.2.x] fixtures: fix catastrophic performance problem in reorder_items#12414
Merged
bluetech merged 1 commit intopytest-dev:8.2.xfrom Jun 4, 2024
Merged
[8.2.x] fixtures: fix catastrophic performance problem in reorder_items#12414bluetech merged 1 commit intopytest-dev:8.2.xfrom
reorder_items#12414bluetech merged 1 commit intopytest-dev:8.2.xfrom
Conversation
…ems` Manual minimal backport from commit e89d23b. Fix pytest-dev#12355. In the issue, it was reported that the `reorder_items` has quadratic (or worse...) behavior with certain simple parametrizations. After some debugging I found that the problem happens because the "Fix items_by_argkey order" loop keeps adding the same item to the deque, and it reaches epic sizes which causes the slowdown. I don't claim to understand how the `reorder_items` algorithm works, but if as far as I understand, if an item already exists in the deque, the correct thing to do is to move it to the front. Since a deque doesn't have such an (efficient) operation, this switches to `OrderedDict` which can efficiently append from both sides, deduplicate and move to front.
Pierre-Sassoulas
approved these changes
Jun 4, 2024
webknjaz
reviewed
Mar 19, 2025
| for key in argkeys_cache[scope].get(item, []): | ||
| items_by_argkey[scope][key].appendleft(item) | ||
| scoped_items_by_argkey[key][item] = None | ||
| scoped_items_by_argkey[key].move_to_end(item, last=False) |
Member
There was a problem hiding this comment.
Oh.. So this was backported after all. Makes sense given that the regression appeared in v8.2.2.
webknjaz
added a commit
to webknjaz/multidict
that referenced
this pull request
Mar 19, 2025
This patch temporarily restricts pytest version below 8.2.2 under PyPy due to a discovered regression that it introduced [[1]]. The regression has been observed on at least `pypy3.9-7.3.16`, `pypy3.10-7.3.19` and `pypy3.11-7.3.19`. It can be triggered by running the following in affected runtimes: pytest --collect-only --no-cov tests/test_abc.py tests/test_copy.py tests/test_incorrect_args.py tests/test_multidict.py tests/test_mypy.py tests/test_pickle.py tests/test_types.py tests/test_update.py tests/test_version.py [1]: pytest-dev/pytest#13312 [2]: pytest-dev/pytest#12414 [3]: pytest-dev/pytest#12409
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Manual minimal backport from commit e89d23b.