alisaifee / limits

Rate limiting using various strategies and storage backends such as redis & memcached
https://limits.readthedocs.org
MIT License
423 stars 58 forks source link

incorrect `__slots__` #121

Closed cwells closed 2 years ago

cwells commented 2 years ago

I'm presuming this was intended to be GRANULARITY:

https://github.com/alisaifee/limits/blob/5facdd5c2b6a44006d60a96b3ab1152367e3c176/limits/limits.py#L65

Confusing when dir(rate) shows a non-existent attribute.

alisaifee commented 2 years ago

Actually it shouldn't be GRANULARITIES since that is a class, not instance var.

alisaifee commented 2 years ago

Thanks for the report, turns out the current implementation (even if we ignore the extra granularities slot), was actually causing the objects to be as large as if they would be without __slots__

No Slots

>>> from pympler.asizeof import asizeof
>>> from limits import parse_many
>>> asizeof(parse_many(",".join(["1/second"] * 100000))) / 1024.0 / 1024.0
15.259986877441406

Slots declared on base class

>>> from pympler.asizeof import asizeof
>>> from limits import parse_many
>>> asizeof(parse_many(",".join(["1/second"] * 100000))) / 1024.0 / 1024.0
15.259811401367188

With slots declared on derived class (RateLimitIterPerSecond etc..)

>>> from pympler.asizeof import asizeof
>>> from limits import parse_many
>>> asizeof(parse_many(",".join(["1/second"] * 100000))) / 1024.0 / 1024.0
6.1045379638671875
alisaifee commented 2 years ago

Addressed in 2.6.0