-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Speed up Deferred: isinstance() is slow #12223
Comments
IIRC we used to have a |
I got curious and created this: import timeit
setup = 'from twisted.internet.defer import Deferred\nx = Deferred()\nb=False'
fast = '''
if x.__class__ is Deferred or isinstance(x, Deferred):
b = True
'''
slow = '''
if isinstance(x, Deferred):
b = True
'''
N = 10_000_000
T = timeit.timeit(stmt=fast, number=N, setup=setup)
print(T)
T = timeit.timeit(stmt=slow, number=N, setup=setup)
print(T) ...which gave me approximately this: 0.09645763300068211
0.1443577739992179 |
The problem with this benchmark is that it goes faster only if |
Deferred callback does an
instance(result, Deferred)
in the hot path, which is a pretty expensive operation.The text was updated successfully, but these errors were encountered: