Skip to content

Commit

Permalink
chore: add comment about weakref memory usage and performance
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Dec 1, 2022
1 parent cc61e67 commit f3e48b4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions disnake/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ def clear(
self, *, views: bool = True, application_commands: bool = True, modals: bool = True
) -> None:
self.user: ClientUser = MISSING
# NOTE: without weakrefs, these user objects would otherwise be kept in memory indefinitely.
# However, using weakrefs here unfortunately has a few drawbacks:
# - the weakref slot + object in user objects likely results in a small increase in memory usage
# - accesses on `_users` are slower, e.g. `__getitem__` takes ~1us with weakrefs and ~0.2us without
self._users: weakref.WeakValueDictionary[int, User] = weakref.WeakValueDictionary()
self._emojis: Dict[int, Emoji] = {}
self._stickers: Dict[int, GuildSticker] = {}
Expand Down

0 comments on commit f3e48b4

Please sign in to comment.