[Django] #33502: Consider using a sparse-representation of fields.

19 views
Skip to first unread message

Django

unread,
Feb 7, 2022, 1:03:11 PM2/7/22
to django-...@googlegroups.com
#33502: Consider using a sparse-representation of fields.
-------------------------------------+-------------------------------------
Reporter: Collin | Owner: nobody
Anderson |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: dev
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/33502>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 7, 2022, 1:03:40 PM2/7/22
to django-...@googlegroups.com
#33502: Consider using a sparse-representation of fields.
-------------------------------------+-------------------------------------
Reporter: Collin Anderson | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Collin Anderson):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/15410

--
Ticket URL: <https://code.djangoproject.com/ticket/33502#comment:1>

Django

unread,
Feb 8, 2022, 12:57:17 AM2/8/22
to django-...@googlegroups.com
#33502: Move Field attributes to class attributes.

-------------------------------------+-------------------------------------
Reporter: Collin Anderson | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Keryn Knight (added)
* status: new => closed
* resolution: => needsinfo


Comment:

Thanks for the idea! This is a bit similar to the
[https://github.com/django/django/pull/15126 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/33502#comment:2>

Reply all
Reply to author
Forward
0 new messages