volatilityfoundation / volatility3

Volatility 3.0 development
http://volatilityfoundation.org/
Other
2.72k stars 463 forks source link

Fix misuse of all() and any() functions across the codebase #1284

Closed gcmoreira closed 1 month ago

gcmoreira commented 1 month ago

We are misusing the all() and any() Python's built-in functions. Wrapping the iterable in [] converts it into a list before the function is called, which unnecessarily increases the runtime to the worst-case which is O(n) in every case.

What we are currently doing:

>>> import timeit
>>> timeit.timeit('any([n > 0 for n in range(10000)])', number=10000)
4.729606243010494

How it should be:

>>> import timeit
>>> timeit.timeit('any(n > 0 for n in range(10000))', number=10000)
0.019788431003689766
gcmoreira commented 1 month ago

@ikelos let me know if you want me to change any version number