From dab2a7cd52538f872916c539c4c7cbe2eb5a0eee Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 19 Mar 2021 15:35:56 +0000 Subject: [PATCH] [IMP] core: make field._modules a tuple instead of a set On a registry with 296 modules, this saves 700 kilobytes of memory, which is about 5% of the registry's memory footprint. --- odoo/fields.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/odoo/fields.py b/odoo/fields.py index 3f4dbd90576..f7f63c8d4e6 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -363,7 +363,7 @@ class Field(MetaField('DummyField', (object,), {})): attrs['model_name'] = model_class._name attrs['name'] = name attrs['_module'] = modules[-1] if modules else None - attrs['_modules'] = set(modules) + attrs['_modules'] = tuple(set(modules)) # initialize ``self`` with ``attrs`` if name == 'state': @@ -562,8 +562,8 @@ class Field(MetaField('DummyField', (object,), {})): # add modules from delegate and target fields; the first one ensures # that inherited fields introduced via an abstract model (_inherits # being on the abstract model) are assigned an XML id - self._modules.update(model._fields[self.related[0]]._modules) - self._modules.update(field._modules) + delegate_field = model._fields[self.related[0]] + self._modules = tuple({*self._modules, *delegate_field._modules, *field._modules}) def traverse_related(self, record): """ Traverse the fields of the related field `self` except for the last