[Piglit] [Patch v2 02/13] framework/exectest.py: Use __slots__ to limit memory consumption

Dylan Baker baker.dylan.c at gmail.com
Tue May 13 11:58:06 PDT 2014


On Tuesday, May 13, 2014 14:51:00 Ilia Mirkin wrote:
> On Tue, May 13, 2014 at 2:38 PM, Dylan Baker <baker.dylan.c at gmail.com> wrote:
> > This uses python's __slots__ attribute on Test. This limits the
> > attributes of the class to exclusively those defined by the __slots__
> > attribute. This saves memory since python doesn't need to allocate
> > additional memory for new attributes that might be added.
> >
> > It is perfectly valid to extend this in a subclass by setting __slots__,
> > that list is appended to the lists in the parent classes, so only new
> > names need to be added.
> >
> > This cut the memory usage of loading tests.quick (and only loading) on
> > my system from ~32M to ~24M.
> >
> > Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
> > ---
> >  framework/exectest.py  | 2 ++
> >  framework/gleantest.py | 1 -
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/framework/exectest.py b/framework/exectest.py
> > index 18f4818..c863d20 100644
> > --- a/framework/exectest.py
> > +++ b/framework/exectest.py
> > @@ -50,6 +50,8 @@ else:
> >
> >  class Test(object):
> >      ENV = Environment()
> > +    __slots__ = ['ENV', 'run_concurrent', 'env', 'result', 'cwd', '_command',
> > +                 '_test_hook_execute_run']
> 
> Does ENV need to be in the slots? It's a class-level attribute, not
> instance-level. I played around with some quick tests, and it seems to
> work OK, but I didn't do anything exhaustive...

It doesn't need to be in there, but if you want to override it on a
per instance case it needs to be there. I guess the question to ask
is whether it's a legitimate use case to override Test.ENV. I don't
care either way.

[snip]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140513/65268333/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20140513/65268333/attachment.sig>


More information about the Piglit mailing list