[issue19640] Drop _source attribute of namedtuple (waste memory)

STINNER Victor report at bugs.python.org
Tue Mar 18 09:57:54 CET 2014


STINNER Victor added the comment:

namedtuple_source.patch: Replace _source attribute wasting memory with a property generating the source on demand. The patch adds also unit test for the verbose attribute (which is public and documented, even it is said to be "outdated").

The patch removes also repr_fmt and num_fields parameters of the class definition template, compute these values using the list of fields.

I suggested to change Python 3.4.1 and 3.5.

Test script:
---
import email
import http.client
import pickle
import test.regrtest
import test.test_os
import tracemalloc
import xmlrpc.server

snap = tracemalloc.take_snapshot()
with open("dump.pickle", "wb") as fp:
    pickle.dump(snap, fp, 2)
---

With the patch, the memory footprint is reduced by 176 kB.

----------
keywords: +patch
title: Drop _source attribute of namedtuple -> Drop _source attribute of namedtuple (waste memory)
type:  -> resource usage
versions: +Python 3.5
Added file: http://bugs.python.org/file34484/namedtuple_source.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19640>
_______________________________________


More information about the Python-bugs-list mailing list