From 24ec9ab84aaabbeffd22f237e2dd89c0d63c0b25 Mon Sep 17 00:00:00 2001 From: Florian Best Date: Wed, 3 Nov 2021 13:55:03 +0100 Subject: [PATCH] feat[serializers]: specify empty __slots__ for serializer classes a little bit gain of memory usage for multiple instances --- shared_memory_dict/serializers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shared_memory_dict/serializers.py b/shared_memory_dict/serializers.py index 18e6c36..1069180 100644 --- a/shared_memory_dict/serializers.py +++ b/shared_memory_dict/serializers.py @@ -25,6 +25,8 @@ def loads(self, data: bytes) -> dict: class JSONSerializer: + __slots__ = () + encoder = json.JSONEncoder decoder = json.JSONDecoder @@ -43,6 +45,9 @@ def loads(self, data: bytes) -> dict: class PickleSerializer: + + __slots__ = () + def dumps(self, obj: dict) -> bytes: try: return pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)