Improve performance on larger cmdsets, and don't store cmdset cache as weakrefs to avoid GC hits.

This commit is contained in:
Ben Longden 2025-08-28 11:12:33 +01:00
parent 4b47f886bb
commit ddd54bdd15
2 changed files with 3 additions and 3 deletions

View file

@ -32,7 +32,6 @@ from collections import defaultdict
from copy import copy
from itertools import chain
from traceback import format_exc
from weakref import WeakValueDictionary
from django.conf import settings
from django.utils.translation import gettext as _
@ -49,7 +48,7 @@ _IN_GAME_ERRORS = settings.IN_GAME_ERRORS
__all__ = ("cmdhandler", "InterruptCommand")
_GA = object.__getattribute__
_CMDSET_MERGE_CACHE = WeakValueDictionary()
_CMDSET_MERGE_CACHE = {}
# tracks recursive calls by each caller
# to avoid infinite loops (commands calling themselves)

View file

@ -248,7 +248,8 @@ class CmdSet(object, metaclass=_CmdSetMeta):
if cmdset_a.duplicates and cmdset_a.priority == cmdset_b.priority:
cmdset_c.commands.extend(cmdset_b.commands)
else:
cmdset_c.commands.extend([cmd for cmd in cmdset_b if cmd not in cmdset_a])
existing_commands = set(cmdset_a.commands)
cmdset_c.commands.extend([cmd for cmd in cmdset_b if cmd not in existing_commands])
return cmdset_c
def _intersect(self, cmdset_a, cmdset_b):