-
Notifications
You must be signed in to change notification settings - Fork 323
add code to lazily precompute multiplication tables #212
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
Conversation
…HON_ECDSA_ENABLE_LAZY_PRECOMPUTE
The CI also failed: https://travis-ci.org/github/warner/python-ecdsa/builds/742220130 |
ok, pushed adjustments based on your feedback, and tested on cpy and pypy:
2 notes:
|
check the CI results: https://travis-ci.org/github/warner/python-ecdsa/pull_requests
the solution to deadlocking is not locking in fewer places but to lock in correct places; here we need to acquire reader lock when checking if the precompute is initialised, free it, and then acquire a writer lock if it wasn't initialised; then after getting the writer lock we need to check again for initialisation |
I've updated the PR which should reflect ^ now .. |
src/ecdsa/ellipticcurve.py
Outdated
@@ -34,6 +34,7 @@ | |||
# Written in 2005 by Peter Pearson and placed in the public domain. | |||
|
|||
from __future__ import division | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused import
# since we lack promotion of read-locks to write-locks, we do a | ||
# "acquire-read-lock check, acquire-write-lock plus recheck" cycle .. | ||
try: | ||
self._scale_lock.reader_acquire() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's _scale_lock
because it was used for scale()
but now we also use it for precompute... maybe change its name to _update_lock
?
also few previous versions failed in CI because of excessive line length, you may want to run |
thanks for your time and for reviewing! pls merge.
|
the builds take hours because travis limited the number of free workers recently: https://www.traviscistatus.com/#month don't know why exactly, unfortunately I don't have access to administer it to fix the dismissal of stale PRs or lack of CI status in PRs either... I'll send an email to Warner tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, looks good, but I'll wait until the CI finishes before merging
thanks for approving!
|
merged, thank you! |
this is an attempt to fix #180
the does not change any existing behavior, but adds new behavior:
when
PYTHON_ECDSA_ENABLE_LAZY_PRECOMPUTE
env var is set, the multiplication tables for curves are only precomputed upon first use.without the env var being set (the current behavior), tables for all supported curves are precomputed at import time regardless of whether the curves are used in the user app at all.
effect can be seen in this test:
using
test.py
: