Skip to content

fixtures: remove dirty optimization for request.getfixturevalue()#14290

Open
bluetech wants to merge 1 commit intomainfrom
rm-getfixturevalue-opt
Open

fixtures: remove dirty optimization for request.getfixturevalue()#14290
bluetech wants to merge 1 commit intomainfrom
rm-getfixturevalue-opt

Conversation

@bluetech
Copy link
Member

Currently for each Function we copy the FunctionDefinition's _arg2fixturedefs. This is done due to an optimization for a dynamic request.getfixturevalue() when the fixture name wasn't statically request. In this case, we save the dynamically-found FixtureDef in _arg2fixturedef, such that if it is requested again in the same item, it is returned immediately instead of doing a _matchfactories check again.

I've always disliked this copy and mutation. The _arg2fixturedefs shenanigans performed during collection are hard enough to follow, and this only adds to the complexity, due to the mutability and having multiple different _arg2fixturedefs with different contents.

So summing up:

Pros: faster repeated request.getfixturevalue() in same test
Cons: complexity (reasoning about mutability), extra copy

Since request.getfixturevalue() is mostly a last-resort thing, so shouldn't be too common, and repeated calls to it in the same test should be even less common, and if so _matchfactories shouldn't be that slow, let's remove this optimization. If this causes a noticeable slowdown for someone, we can consider bringing it back, though perhaps in a cleaner way.

Currently for each `Function` we copy the `FunctionDefinition`'s
`_arg2fixturedefs`. This is done due to an optimization for a dynamic
`request.getfixturevalue()` when the fixture name wasn't statically
request. In this case, we save the dynamically-found `FixtureDef` in
`_arg2fixturedef`, such that if it is requested again in the same item,
it is returned immediately instead of doing a `_matchfactories` check
again.

I've always disliked this copy and mutation. The `_arg2fixturedefs`
shenanigans performed during collection are hard enough to follow, and
this only adds to the complexity, due to the mutability and having
multiple different `_arg2fixturedefs` with different contents.

So summing up:

Pros: faster repeated `request.getfixturevalue()` in same test
Cons: complexity (reasoning about mutability), extra copy

Since `request.getfixturevalue()` is mostly a last-resort thing, so
shouldn't be too common, and *repeated* calls to it in the same test
should be even less common, and if so `_matchfactories` shouldn't be
*that* slow, let's remove this optimization. If this causes a noticeable
slowdown for someone, we can consider bringing it back, though perhaps
in a cleaner way.
@bluetech bluetech added the skip news used on prs to opt out of the changelog requirement label Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news used on prs to opt out of the changelog requirement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant