ircmsgs: Internalize prefix, server_tags keys, and command.

prefixes can be rather long, they have rather small cardinality, and
they are repeated a lot in the history; so they take up a sizeable
portion of memory.

And let's also internalize commands and server_tags keys
while I'm at it.
This commit is contained in:
Valentin Lorentz 2020-05-17 21:11:14 +02:00
parent 2682e4cb48
commit c9c05cf8e1

View File

@ -36,6 +36,7 @@ object (which, as you'll read later, is quite...full-featured :))
"""
import re
import sys
import time
import base64
import datetime
@ -81,7 +82,7 @@ def parse_server_tags(s):
server_tags = {}
for tag in s.split(';'):
if '=' not in tag:
server_tags[tag] = None
server_tags[sys.intern(tag)] = None
else:
(key, value) = tag.split('=', 1)
value = unescape_server_tag_value(value)
@ -89,7 +90,7 @@ def parse_server_tags(s):
# "Implementations MUST interpret empty tag values (e.g. foo=)
# as equivalent to missing tag values (e.g. foo)."
value = None
server_tags[key] = value
server_tags[sys.intern(key)] = value
return server_tags
def format_server_tags(server_tags):
parts = []
@ -212,6 +213,8 @@ class IrcMsg(object):
self.server_tags = {}
else:
self.server_tags = server_tags
self.prefix = sys.intern(self.prefix)
self.command = sys.intern(self.command)
self.args = tuple(self.args)
if isUserHostmask(self.prefix):
(self.nick,self.user,self.host)=ircutils.splitHostmask(self.prefix)