diff options
author | Erik Johnston <erik@matrix.org> | 2015-01-06 18:51:03 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-01-06 18:51:03 +0000 |
commit | dfa05f0cd69779f21ae9b1085c40079440f87d3b (patch) | |
tree | 5bda263705c0bf37b0aff8e60aab2662f3fc578f /synapse/events | |
parent | Use time.time() instead of time.clock() (diff) | |
download | synapse-dfa05f0cd69779f21ae9b1085c40079440f87d3b.tar.xz |
Optimize FrozenEvent creation
Diffstat (limited to 'synapse/events')
-rw-r--r-- | synapse/events/__init__.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py index 5dca04d923..6030c5887a 100644 --- a/synapse/events/__init__.py +++ b/synapse/events/__init__.py @@ -20,7 +20,7 @@ import copy class _EventInternalMetadata(object): def __init__(self, internal_metadata_dict): - self.__dict__ = copy.deepcopy(internal_metadata_dict) + self.__dict__ = internal_metadata_dict def get_dict(self): return dict(self.__dict__) @@ -49,10 +49,10 @@ def _event_dict_property(key): class EventBase(object): def __init__(self, event_dict, signatures={}, unsigned={}, internal_metadata_dict={}): - self.signatures = copy.deepcopy(signatures) - self.unsigned = copy.deepcopy(unsigned) + self.signatures = signatures + self.unsigned = unsigned - self._event_dict = copy.deepcopy(event_dict) + self._event_dict = event_dict self.internal_metadata = _EventInternalMetadata( internal_metadata_dict @@ -112,10 +112,16 @@ class EventBase(object): class FrozenEvent(EventBase): def __init__(self, event_dict, internal_metadata_dict={}): - event_dict = copy.deepcopy(event_dict) + event_dict = dict(event_dict) - signatures = copy.deepcopy(event_dict.pop("signatures", {})) - unsigned = copy.deepcopy(event_dict.pop("unsigned", {})) + # Signatures is a dict of dicts, and this is faster than doing a + # copy.deepcopy + signatures = { + name: {sig_id: sig for sig_id, sig in sigs.items()} + for name, sigs in event_dict.pop("signatures", {}).items() + } + + unsigned = dict(event_dict.pop("unsigned", {})) frozen_dict = freeze(event_dict) |