Skip to content

Conversation

@tiran
Copy link
Member

@tiran tiran commented Mar 28, 2019

Accumulate certificates in a set instead of doing a costly list contain
operation. A Windows cert store can easily contain over hundred
certificates. The old code would result in way over 5,000 comparison
operations.

Signed-off-by: Christian Heimes [email protected]

Untested, uncompiled C code. Let's see what the Windows build bot has to say.

https://bugs.python.org/issue35941

@tiran tiran force-pushed the bpo-35941-performance branch from e78c191 to 7c5f0e4 Compare March 28, 2019 20:53
@zooba
Copy link
Member

zooba commented Mar 28, 2019

Looks like one of the elements is indeed not hashable, which is why you need the list. But a set should be able to compare equal properly even within a tuple, so the previous code was fine (if slow).

If you want to go as far as using a dict keyed off the certificate bytes and storing all matches in lists then you could reduce the number of comparisons significantly, but I don't think this is necessarily performance sensitive enough to be worth it. Maybe change the Python code to cache the result unless it's explicitly called again?

@tiran
Copy link
Member Author

tiran commented Mar 28, 2019

The Windows cert store can contain more than a hundred unique root certs. We'll end up with 5,000 to 10,000 comparisons to build a list of unique items. It's a performance issue.

I have figured out why it's failing. parseKeyUsage returns a set. I could turn the result into a frozenset.

@tiran tiran force-pushed the bpo-35941-performance branch from 7c5f0e4 to 9774065 Compare March 28, 2019 23:05
@zooba
Copy link
Member

zooba commented Mar 29, 2019

Looks like it's fine apart from a type check in test_enum_certificates

Modules/_ssl.c Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could remove this else statement (also in the corresponding code in _ssl_enum_crls_impl).

Accumulate certificates in a set instead of doing a costly list contain
operation. A Windows cert store can easily contain over hundred
certificates. The old code would result in way over 5,000 comparison
operations

Signed-off-by: Christian Heimes <[email protected]>
@tiran tiran force-pushed the bpo-35941-performance branch from 9774065 to a6e73a6 Compare September 9, 2019 12:46
@tiran
Copy link
Member Author

tiran commented Sep 9, 2019

@zooba

@zooba zooba merged commit 915cd3f into python:master Sep 9, 2019
@miss-islington
Copy link
Contributor

Thanks @tiran for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @tiran and @zooba, I could not cleanly backport this to 3.8 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 915cd3f0696cb8a7206754a8fc34d4cd865a1b4a 3.8

@miss-islington
Copy link
Contributor

Sorry @tiran and @zooba, I had trouble checking out the 3.7 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 915cd3f0696cb8a7206754a8fc34d4cd865a1b4a 3.7

zooba pushed a commit to zooba/cpython that referenced this pull request Sep 9, 2019
…GH-12610)

Accumulate certificates in a set instead of doing a costly list contain
operation. A Windows cert store can easily contain over hundred
certificates. The old code would result in way over 5,000 comparison
operations

Signed-off-by: Christian Heimes <[email protected]>
@bedevere-bot
Copy link

GH-15803 is a backport of this pull request to the 3.8 branch.

zooba pushed a commit to zooba/cpython that referenced this pull request Sep 9, 2019
…GH-12610)

Accumulate certificates in a set instead of doing a costly list contain
operation. A Windows cert store can easily contain over hundred
certificates. The old code would result in way over 5,000 comparison
operations

Signed-off-by: Christian Heimes <[email protected]>
@bedevere-bot
Copy link

GH-15804 is a backport of this pull request to the 3.7 branch.

zooba added a commit that referenced this pull request Sep 10, 2019
Accumulate certificates in a set instead of doing a costly list contain
operation. A Windows cert store can easily contain over hundred
certificates. The old code would result in way over 5,000 comparison
operations

Signed-off-by: Christian Heimes <[email protected]>
zooba added a commit that referenced this pull request Sep 10, 2019
Accumulate certificates in a set instead of doing a costly list contain
operation. A Windows cert store can easily contain over hundred
certificates. The old code would result in way over 5,000 comparison
operations

Signed-off-by: Christian Heimes <[email protected]>
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
Accumulate certificates in a set instead of doing a costly list contain
operation. A Windows cert store can easily contain over hundred
certificates. The old code would result in way over 5,000 comparison
operations

Signed-off-by: Christian Heimes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants