Opened 3 years ago
Closed 3 years ago
#33502 closed Cleanup/optimization (needsinfo)
Move Field attributes to class attributes.
Reported by: | Collin Anderson | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Keryn Knight | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This only adds attributes to a field's __dict__
if it has a non default value.
Similar to __slots__
for SafeString
#33465 this could theoretically reduce memory usage, with less chance of breaking things compared to actually using __slots__
.
https://github.com/collinanderson/django/commit/41b2f0d6928b1a837df6d57169313d6b5f535a5d
I'm mostly just throwing this out there to add to the discussion and see what people think. Totally cool if it doesn't get merged.
Change History (2)
comment:1 by , 3 years ago
Has patch: | set |
---|
comment:2 by , 3 years ago
Cc: | added |
---|---|
Resolution: | → needsinfo |
Status: | new → closed |
Summary: | Consider using a sparse-representation of fields. → Move Field attributes to class attributes. |
Thanks for the idea! This is a bit similar to the PR15126. As far as I'm aware access to class attributes are slower than access to instance attributes, so we should benchmark proposed solution and check for performance regression. It'd also be nice to compare the memory usage.
PR: https://github.com/django/django/pull/15410