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

Ilia Mirkin imirkin at alum.mit.edu
Tue May 13 11:51:00 PDT 2014


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...

>
>      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
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list