Skip to content

Some easy micro optimizations to collection #7172

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
merged 4 commits into from
May 6, 2020

Conversation

bluetech
Copy link
Member

@bluetech bluetech commented May 6, 2020

Collectively, on this benchmark run with --collect-only:

import pytest
@pytest.mark.parametrize("x", range(50000))
def test_foo(x): pass

Before:

============================ no tests ran in 11.37s ============================
         23775445 function calls (22920574 primitive calls) in 11.648 seconds

After:

============================ no tests ran in 10.51s ============================
         21725509 function calls (20870638 primitive calls) in 10.931 seconds

The first commit utilizes the fact that dicts are insertion-order preserving on Python>=3.7 to avoid OrderedDict overhead when possible.

The second and third commits apply some micro optimizations to Node.

The fourth applies some minor optimizations to PythonCollector.collect.

bluetech added 4 commits May 6, 2020 11:58
OrderedDict is quite a bit heavier than just a dict.
Turns out it's called alot, and saving the function call makes it
faster.
@bluetech bluetech force-pushed the micro-optimizations-1 branch from 93625fa to 89eee90 Compare May 6, 2020 09:07
@bluetech
Copy link
Member Author

bluetech commented May 6, 2020

I scaled back the last commit a bit after the CI kindly informed me that I had missed some details 😄 Doesn't affect the benchmark results however.

@bluetech bluetech merged commit 8c2c297 into pytest-dev:master May 6, 2020
@bluetech
Copy link
Member Author

bluetech commented May 6, 2020

cc @boxed, #5516

@boxed
Copy link
Contributor

boxed commented May 12, 2020

I had some time to check this and the other changes that have landed in master. I am comparing 5.4.1 and master:

before
after

It's slightly better but it's still very bad.

@boxed
Copy link
Contributor

boxed commented May 12, 2020

I tried pytest 3.10.1 and it's at 7.8s for the parametrize_huge benchmark. Again still very bad, but a lot better than pytest 5. I even checked 3.6 because I have a memory of this being faster on our suite at work: 7.5s so basically the same.

Nose2 beating out hammett on parametrize_huge is pretty impressive. Don't really understand how :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants