In a number of places, the use of the @lru_cache decorator, which will cache previously calculated values and return them in O(1) on future calls, may massively improve performance. We should Kkeep it in mind, see here: https://docs.python.org/3/library/functools.html#functools.lru_cache