- Notifications
You must be signed in to change notification settings - Fork11.2k
Reducing memory footprint ofRequest object: __slots__ and lazy evaluation#7036
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
Request object: __slots__ and lazy evaluationRequest object: __slots__ and lazy evaluationwRAR commentedSep 1, 2025
I think this broke tests. |
albertedwardson commentedSep 1, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oh, sorry, my bad. When I tested locally, I assumed the hanging test case was broken because I was running tests on my work PC with a weird Windows setup and a custom-compiled Python build |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
albertedwardson commentedSep 2, 2025
All unit tests of "request" objects now passing. But I didn't ran full suite locally, can't do it now. |
codecovbot commentedSep 2, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## master #7036 +/- ##==========================================+ Coverage 90.68% 90.95% +0.27%========================================== Files 164 164 Lines 12642 12788 +146 Branches 1643 1663 +20 ==========================================+ Hits 11464 11631 +167+ Misses 891 873 -18+ Partials 287 284 -3
|
This comment was marked as resolved.
This comment was marked as resolved.
albertedwardson commentedSep 2, 2025
@wRAR is there any point for writing tests for setters? |
wRAR commentedSep 3, 2025
Yeah, I think it's useful to make sure the attributes can be assigned, for these and future changes. |
this is mostly ai generatedidk those comments and docstring are helpful imo
this is mostly ai generatedidk those comments and docstring are helpful imo
| @meta.setter | ||
| defmeta(self,value:dict[str,Any]|None)->None: | ||
| self._meta=valueifvalueelseNone |
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.
I think this line can be likeself._meta = value or None.
Becouse{} or None -> None, so zero-value of dict can be ignored.
Uh oh!
There was an error while loading.Please reload this page.
This PR makes such changes:
Python’s
dictobjects are fairly heavy, even when empty. TheRequestobject had a few of them. This PR makes their creation lazy (along with theflagslist), so they are only created when they actually hold data. Previously, they were also created lazily, but once accessed, theRequestobject would keep references to emptydicts/lists.In practice, these could just beNo, this breaks things. E.g.Noneinstead.r.cookies[k]=vwill return newly created empty dict, assignvtokkey, and then discard this dict object since there is no references to it. Once accessed, they will be created and keeped. But when trying to assign empty dict or list to some ofRequestattributes, we won't store them.Added
__slots__toRequestclass and its subclassesBefore
After