You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
I wasn't able to share a flamegraph because my v8 log was too big, but just to emphasize how much CPU this uses, here's screenshots of the processed log (just shows the getter using more CPU than almost anything else in the main process)
I'll probably migrate to buttons, as they're the more proper way of having users click on things - I'd assume discord devs prefer we use buttons. I did check and, although you can put custom emojis on buttons, they don't have this issue, because they use a util that specifically was made to not access the client:
* Resolves a partial emoji object from an {@link EmojiIdentifierResolvable}, without checking a Client.
I'm not sure how to fix this (add an option for caching them? find a way to not need to access client.emojis?). People dont want them cached because they want less memory usage, but people dont think about the cpu usage as much.
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:
discord.js/src/client/Client.js
Line 170 in a08ce7d
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.
Further details:
a08ce7dddb5f056128488392742495398f9e33b5
Relevant client options:
The text was updated successfully, but these errors were encountered: