changeset b569af4f7d88 in modules/party_relationship:default
details:
https://hg.tryton.org/modules/party_relationship?cmd=changeset;node=b569af4f7d88
description:
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
diffstat:
party.py | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)
diffs (37 lines):
diff -r 876665c5fa37 -r b569af4f7d88 party.py
--- a/party.py Mon May 04 12:19:04 2020 +0200
+++ b/party.py Sat Jun 13 09:48:03 2020 +0200
@@ -163,17 +163,15 @@
# 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 @@
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))