Use custom class to store record data

By using a class with slots instead of standard dict, we can reduce a lot the
memory usage to store the record data in the caches and values.
Also we can rely on the data in the cache to exist only for real field which
can be used to create a fast path in ModelStorage.__getattr__.
As now storing data in the cache has no extra cost, we can store data from the
transactional cache in the local. This allow also to have a shorter path in
ModelStorage.__getattr__.
For more memory efficiency, we remove the record from the cache instead of
clearing them. It was better to clear a dict but a record is less expensive to
re-instantiate than clearing.

issue9369
issue9225
review297861002
This commit is contained in:
Cédric Krier committed 2020-06-13 09:48:03 +02:00
1 parent ceaf68c908
commit c2059bddf0
1 file changed
+5 -7
+5 -7
View File
@@ -163,17 +163,15 @@ class RelationAll(Relation, ModelView):
# Clean local cache
for record in all_records:
for record_id in (record.id, record.reverse_id):
local_cache = record._local_cache.get(record_id)
if local_cache:
local_cache.clear()
record._local_cache.pop(record_id, None)
# Clean cursor cache
for cache in Transaction().cache.values():
if cls.__name__ in cache:
cache_cls = cache[cls.__name__]
for record in all_records:
for record_id in (record.id, record.reverse_id):
if record_id in cache[cls.__name__]:
cache[cls.__name__][record_id].clear()
cache_cls.pop(record_id, None)
actions = iter(args)
args = []
@@ -213,10 +211,10 @@ class RelationAll(Relation, ModelView):
for cache in (cache,
list(cache.get('_language_cache', {}).values())):
if cls.__name__ in cache:
cache_cls = cache[cls.__name__]
for record in relations:
for record_id in (record.id, record.reverse_id):
if record_id in cache[cls.__name__]:
del cache[cls.__name__][record_id]
cache_cls.pop(record_id, None)
Relation.delete(cls.convert_instances(relations))