Created on 2021-01-23.23:13:32 by ced, last changed 1 week ago by pokoli.
Last version is faster than original implementation and consume less memory.
lru-dict is not a possible alternative as it is missing default_factory.
And also time is not the only measure but memory usage is also. As lru-dict is using a dict and a list, it consumes more memory. I measured on similar test to be 10% more.
As mentioned in the review, the proposed patch is much slower than current implementation.
However, using this script:
d = LRUDict(1000) for x in range(10_000_000): d[x] = 1
I see a 5% performance improvement simply "inlining" _check_cache_size() code in __setitem__() method.
I also tested lru-dict (https://pypi.org/project/lru-dict/) and it is 5.8x faster than current implementation.
These are the results for the mentioned snippet (10M assignments):
All results are the median value of 5 runs.
This could be implemented only when we will drop support of Python3.6 because insertion-order preservation nature of dict as only be declared as specification of the language in Python 3.7.
The main advantage is that it prevent the creation of the doubly linked list of OrderedDict.
|2021-03-31 12:08:51||pokoli||set||nosy: + pokoli|
|2021-01-24 01:20:52||ced||set||messages: + msg64061|
|2021-01-24 01:19:26||reviewbot||set||messages: + msg64060|
nosy: + albertca
nosy: + reviewbot
status: in-progress -> testing
Showing 10 items. Show all history (warning: this could be VERY long)