[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:38:35 PDT 2014


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']
 
     def __init__(self, command, run_concurrent=False):
         '''
diff --git a/framework/gleantest.py b/framework/gleantest.py
index 4e09d41..2f22c87 100644
--- a/framework/gleantest.py
+++ b/framework/gleantest.py
@@ -34,7 +34,6 @@ class GleanTest(Test):
     def __init__(self, name, **kwargs):
         super(GleanTest, self).__init__([glean_executable, "-o", "-v", "-v",
                                        "-v", "-t", "+" + name])
-        self.name = name
 
     @Test.command.getter
     def command(self):
-- 
2.0.0.rc2



More information about the Piglit mailing list