From 00a0856cc44549a29d5123b997db3a5e593f0896 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 29 May 2019 01:22:36 -0400 Subject: Use a dict instead of getattr for parsing events. Probably not a significant difference but might as well use it here. The basic idea is to cache the getattr calls instead of repeatedly doing it (since they're around 105ns on my machine). The dictionary lookup is about 41ns on my machine. The next step in speeding up library code some more should be in the parser bodies themselves but that's a problem to tackle another day. --- discord/state.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'discord/state.py') diff --git a/discord/state.py b/discord/state.py index f04d6ee7..d56b9e75 100644 --- a/discord/state.py +++ b/discord/state.py @@ -33,6 +33,7 @@ import itertools import logging import math import weakref +import inspect from .guild import Guild from .activity import _ActivityTag @@ -88,6 +89,11 @@ class ConnectionState: self._activity = activity self._status = status + self.parsers = parsers = {} + for attr, func in inspect.getmembers(self): + if attr.startswith('parse_'): + parsers[attr[6:].upper()] = func + self.clear() def clear(self): -- cgit v1.2.3