-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Memory usage optimization on Serializer class #7250
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
Comments
@tomchristie Do you have any thoughts on this ? |
Thanks for looking into this - certainly interesting. Okay, so this is required if Given that the browsable API is on by default, I think this would be quite a big change for us to make, and I'd rather we just let the garbage collector do what garbage collectors do. If there was a way to achieve this that had minimal impact on existing projects or existing behavior then perhaps there'd be something to consider. |
Took a brief look yesterday - the That all said, I'm kind of inclined to just get rid of |
If there's an easy route onto refactoring the browsable API renderer so that it's not required, then sure, that sounds like a good plan. |
Hi @tomchristie ! I've made a PR that fixes the issue, what do you think about it ? |
Steps to reproduce
Lets say we have model like this:
and serializer like this:
and whenever we serialize python obj, the
data
property has reference to serializer:It works fine on small objects like in the example, but it starts consuming more memory with larger querysets and nested Serializers, just because of that
data.serializer
reference. Python reference counter cannot delete thedata.serializer
object, becausedata
property references on that, and such a way we have to wait until GC collects it.The
data.serializer
reference is only used (at least it is single usage I found) in HTMLFormRenderer and it looks like overhead. Also I'm pretty sure there are lots of projects the do not use the renderer at all, but have to "suffer" from that extra memory usage.If I change our serializer like below, it consumes less memory:
So, my point is to make the
serializer
reference optional, depending ifHTMLFormRenderer
is used or not, or pass it via renderer context.and then in serializer do:
Just an idea.
Thoughts ?
PS.
Ready to submit a PR
The text was updated successfully, but these errors were encountered: