Skip to content
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

incorrect __slots__ #121

Closed
cwells opened this issue Apr 24, 2022 · 3 comments
Closed

incorrect __slots__ #121

cwells opened this issue Apr 24, 2022 · 3 comments
Labels

Comments

@cwells
Copy link

cwells commented Apr 24, 2022

I'm presuming this was intended to be GRANULARITY:

__slots__ = ["namespace", "amount", "multiples", "granularity"]

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

@alisaifee
Copy link
Owner

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

@alisaifee
Copy link
Owner

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 alisaifee added the bug label Apr 25, 2022
@alisaifee
Copy link
Owner

Addressed in 2.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants