Skip to content
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

test_typing: test_many_weakrefs takes many seconds #110178

Closed
AlexWaygood opened this issue Oct 1, 2023 · 1 comment
Closed

test_typing: test_many_weakrefs takes many seconds #110178

AlexWaygood opened this issue Oct 1, 2023 · 1 comment
Assignees
Labels
tests Tests in the Lib/test dir topic-typing type-bug An unexpected behavior, bug, or error

Comments

@AlexWaygood
Copy link
Member

AlexWaygood commented Oct 1, 2023

Bug report

Bug description:

TypeVarTests.test_many_weakrefs in test_typing takes far longer than any other test in test_typing if you're using a debug build of CPython, slowing down test_typing considerably:

>python Lib/test/test_typing.py --durations 5
Running Debug|x64 interpreter...
.............................................................................................................................................................................................................................................s.....................................................................................................................................................................................................................................................................................................................................................................
Slowest test durations
----------------------------------------------------------------------
5.090s     test_many_weakrefs (__main__.TypeVarTests.test_many_weakrefs)
0.206s     test_variadic_parameters (__main__.GenericAliasSubstitutionTests.test_variadic_parameters)
0.082s     test_two_parameters (__main__.GenericAliasSubstitutionTests.test_two_parameters)
0.057s     test_special_attrs (__main__.SpecialAttrsTests.test_special_attrs)
0.044s     test_var_substitution (__main__.TypeVarTupleTests.test_var_substitution)

----------------------------------------------------------------------
Ran 594 tests in 6.714s

OK (skipped=1)

The test was added in #108517, as a regression test for #108295.

The slowdown caused by this test is much less pronounced if you use a PGO-optimised non-debug build, but the test still takes much longer than any other test in test_typing on my machine:

>python Lib/test/test_typing.py --durations 5
Running PGUpdate|x64 interpreter...
.............................................................................................................................................................................................................................................s.....................................................................................................................................................................................................................................................................................................................................................................
Slowest test durations
----------------------------------------------------------------------
0.379s     test_many_weakrefs (__main__.TypeVarTests.test_many_weakrefs)
0.026s     test_variadic_parameters (__main__.GenericAliasSubstitutionTests.test_variadic_parameters)
0.014s     test_two_parameters (__main__.GenericAliasSubstitutionTests.test_two_parameters)
0.007s     test_etree (__main__.UnionTests.test_etree)
0.004s     test_var_substitution (__main__.TypeVarTupleTests.test_var_substitution)

----------------------------------------------------------------------
Ran 594 tests in 0.610s

OK (skipped=1)

The test currently attempts to create 100,000 TypeVar weakrefs, 100,000 ParamSpec weakrefs and 100,000 TypeVarTuple weakrefs:

def test_many_weakrefs(self):
# gh-108295: this used to segfault
for cls in (ParamSpec, TypeVarTuple, TypeVar):
with self.subTest(cls=cls):
vals = weakref.WeakValueDictionary()
for x in range(100000):
vals[x] = cls(str(x))
del vals

@JelleZijlstra, reckon we could maybe make that number a little smaller? :)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

@AlexWaygood AlexWaygood added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir topic-typing labels Oct 1, 2023
@JelleZijlstra JelleZijlstra self-assigned this Oct 1, 2023
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue Oct 1, 2023
Confirmed that without the C changes from python#108517, this test still segfaults with only 10 weakrefs.
JelleZijlstra added a commit that referenced this issue Oct 2, 2023
Confirmed that without the C changes from #108517, this test still segfaults with only 10 weakrefs.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 2, 2023
Confirmed that without the C changes from pythonGH-108517, this test still segfaults with only 10 weakrefs.
(cherry picked from commit 732ad44)

Co-authored-by: Jelle Zijlstra <[email protected]>
AlexWaygood pushed a commit that referenced this issue Oct 2, 2023
…110224)

gh-110178: Use fewer weakrefs in test_typing.py (GH-110194)

Confirmed that without the C changes from GH-108517, this test still segfaults with only 10 weakrefs.
(cherry picked from commit 732ad44)

Co-authored-by: Jelle Zijlstra <[email protected]>
@AlexWaygood
Copy link
Member Author

Thanks Jelle!

Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Confirmed that without the C changes from python#108517, this test still segfaults with only 10 weakrefs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants