[Piglit] [PATCH 02/12] framework/exectest.py: Use flyweight pattern for Test

Dylan Baker baker.dylan.c at gmail.com
Fri Apr 25 09:58:50 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 6544ef2..599ea7c 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', '_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.rc0



More information about the Piglit mailing list