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
Fixed #33465 -- Added empty __slots__ to SafeString and SafeData. #15370
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kezabelle Thanks for this patch 👍
You wrote on the ticket:
But this does have a small boost, as Python needn't create an empty dict per object. It's tiny, but I can measure it:
Thanks for doing this. I hope you can find some other places to add |
1d04088
to
00096ee
Compare
Yeah, it was the "marked" part which should've had emphasis on the ticket :) I too see a small difference -- also by exactly I've force-pushed and removed the 'testing cpython' tests ... |
The Template |
Alas, would that it were that simple. There's a couple of compounding issues around the So, it may be workable somehow, but not easy. You could probably get some of the memory savings that using slots would provide, by introducing (Edit: that all said, you have given me an idea of where I might look for separate, semi-related little win, within the same sort of oeuvre, so perhaps we'll see after all) |
Despite inheriting from the str type, every SafeString instance gains an empty __dict__ due to the normal, expected behaviour of type subclassing in Python. Adding __slots__ to SafeData is necessary, because otherwise inheriting from that (as SafeString does) will give it a __dict__ and negate the benefit added by modifying SafeString.
00096ee
to
55022f7
Compare
@kezabelle Thanks 👍 |
ticket is 33465
On the off-chance that's accepted, let's at least check that the tests pass everywhere (i.e. that my asserts are robust enough across multiple versions, tbh)
Place your bets on my getting linter errors ... ;)