Skip to content

Performance issue with client.emojis getter #6248

Closed
@gc

Description

@gc

Please describe the problem you are having in as much detail as possible:
I did some profiling of my bot, and found DJS doing quite a large amount of cpu work here:

get emojis() {

I did a couple checks, and this is called many times, for example every time I add a reaction to a message, because those classes (e.g. Message, MessageReaction, ReactionCollector) will access client.emojis.resolveEmoji() or something like that. From my reading of the code it looks like its generating a new cache every single time you call it, i.e iterating over every emoji of every guild every time i react to a message.

Also, a quick little test I did was running this in my eval command +eval for (let i = 0; i < 20; i++) this.client.emojis; - which takes 8 seconds to finish, which doesn't seem right. unless for some reason I'm not understanding if its meant to be re-generated on every call or not - in either case, its using a lot of CPU, which really could be improved.

Include a reproducible code sample here, if possible:

For example, just a basic reaction is one place I saw this happening.

await message.react(MyEmojis.Smile);

Further details:

  • discord.js version: a08ce7dddb5f056128488392742495398f9e33b5
  • Node.js version: 14.17.3
  • Operating system: Windows
  • Priority this issue should have – please be realistic and elaborate if possible: Low

Relevant client options:

  • partials: ['USER', 'CHANNEL']
  • gateway intents: 'GUILDS', 'GUILD_MEMBERS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS', 'DIRECT_MESSAGES','DIRECT_MESSAGE_REACTIONS','GUILD_WEBHOOKS'
  • other: none

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions