aboutsummaryrefslogtreecommitdiff
path: root/discord/message.py
diff options
context:
space:
mode:
authorSteven Berler <[email protected]>2016-01-01 04:58:47 -0800
committerRapptz <[email protected]>2016-01-08 13:24:55 -0500
commit10b0b62f50f2730809f9740babb1620e95f05561 (patch)
tree60bf8e6d90b8e14a57c6b97f2d126c0c9adf3ef4 /discord/message.py
parent[commands] Add a way to enable or disable certain commands. (diff)
downloaddiscord.py-10b0b62f50f2730809f9740babb1620e95f05561.tar.xz
discord.py-10b0b62f50f2730809f9740babb1620e95f05561.zip
performance improvements
Replaced server member lists, channel lists, and private channel lists with dicts. This allows O(1) lookups and removes (previously it would be an O(N) operation to lookup or remove). I did pretty extensive testing and benchmarking to compare the performance of using lists vs using dicts. Iterating through lists to find an item is only faster in the average case for extremely small lists (less than 3 items). For 100 items, using a dict is about 10 times faster on average (and about 100 times faster for 1000 items). The overhead in dicts is in memory usage and initial creation time. Creating and populating a dict is about 2 to 3 times slower than creating and appending items to a list. However this cost is still tiny. For 1000 items this equates to about a 70 microsecond difference (on an i7 CPU) for populating the entire dict. The memory overhead for a dict (compared to a list) is about 25-60 KB per 1000 items (can vary depending on dict resizing). Originally I wanted to use OrderedDicts to presereve order, but in my testing OrderedDicts have about 6x the memory overhead compared to normal dicts.
Diffstat (limited to 'discord/message.py')
-rw-r--r--discord/message.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/discord/message.py b/discord/message.py
index af431f03..376e5a27 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -122,13 +122,13 @@ class Message:
if self.channel is not None:
for mention in mentions:
id_search = mention.get('id')
- member = utils.find(lambda m: m.id == id_search, self.server.members)
+ member = self.server.get_member(id_search)
if member is not None:
self.mentions.append(member)
if self.server is not None:
for mention in self.raw_channel_mentions:
- channel = utils.find(lambda m: m.id == mention, self.server.channels)
+ channel = self.server.get_channel(mention)
if channel is not None:
self.channel_mentions.append(channel)
@@ -191,6 +191,6 @@ class Message:
if not self.channel.is_private:
self.server = self.channel.server
- found = utils.find(lambda m: m.id == self.author.id, self.server.members)
+ found = self.server.get_member(self.author.id)
if found is not None:
self.author = found