diff options
author | Amber Brown <hawkowl@atleastfornow.net> | 2018-06-28 14:49:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-28 14:49:57 +0100 |
commit | 6350bf925e8651f2fae70a1e7eb7182e9161c34a (patch) | |
tree | 35e766fcb2dabcd1e8978c417709b353d5fdf4bc /synapse/replication | |
parent | Revert "Revert "Try to not use as much CPU in the StreamChangeCache"" (#3454) (diff) | |
download | synapse-6350bf925e8651f2fae70a1e7eb7182e9161c34a.tar.xz |
Attempt to be more performant on PyPy (#3462)
Diffstat (limited to 'synapse/replication')
-rw-r--r-- | synapse/replication/tcp/commands.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/synapse/replication/tcp/commands.py b/synapse/replication/tcp/commands.py index 12aac3cc6b..f3908df642 100644 --- a/synapse/replication/tcp/commands.py +++ b/synapse/replication/tcp/commands.py @@ -19,13 +19,17 @@ allowed to be sent by which side. """ import logging -import simplejson +import platform +if platform.python_implementation() == "PyPy": + import json + _json_encoder = json.JSONEncoder() +else: + import simplejson as json + _json_encoder = json.JSONEncoder(namedtuple_as_object=False) logger = logging.getLogger(__name__) -_json_encoder = simplejson.JSONEncoder(namedtuple_as_object=False) - class Command(object): """The base command class. @@ -102,7 +106,7 @@ class RdataCommand(Command): return cls( stream_name, None if token == "batch" else int(token), - simplejson.loads(row_json) + json.loads(row_json) ) def to_line(self): @@ -300,7 +304,7 @@ class InvalidateCacheCommand(Command): def from_line(cls, line): cache_func, keys_json = line.split(" ", 1) - return cls(cache_func, simplejson.loads(keys_json)) + return cls(cache_func, json.loads(keys_json)) def to_line(self): return " ".join(( @@ -329,7 +333,7 @@ class UserIpCommand(Command): def from_line(cls, line): user_id, jsn = line.split(" ", 1) - access_token, ip, user_agent, device_id, last_seen = simplejson.loads(jsn) + access_token, ip, user_agent, device_id, last_seen = json.loads(jsn) return cls( user_id, access_token, ip, user_agent, device_id, last_seen |