Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(Presence): prefer boolean client status comparison before activity checks #10213

Merged
merged 3 commits into from
Apr 20, 2024

Conversation

JMTK
Copy link
Contributor

@JMTK JMTK commented Apr 14, 2024

Please describe the changes this PR makes and why it should be merged:
Prefer boolean client status comparison before activity checks. This vastly helps performance in scenarios where the only presence change is a client status change, such as going from mobile to desktop. While this change seems very trivial, presences are by-far the highest ingress event for the websockets so this can have pretty beneficial performance impact if we're able to take advantage of it

I pulled out a presence that had more than 3 activities as a base. In all screenshots, the bottom is the current code, top is the new code. Here are my findings:

Scenario 1

Old/New presences have no difference between them. Pretty much equal performance
image

Scenario 2

This was the ideal scenario that I was making this PR for. The only difference between the presences is the client status is "desktop" instead of "mobile". In this case we were able to short-circuit the activity comparisons.
image

Scenario 3

The only difference between the presences is in the activities, client status is the same.
image

On my personal Discord bot, I receive ~39000 presence updates in a 5 minute span. If I'm able to shave off 2 function calls from the stack on even 1/100 of those, that would remove 780 function calls. I think it would be worth it.

Status and versioning classification:
Patch

@JMTK JMTK requested a review from a team as a code owner April 14, 2024 19:28
Copy link

vercel bot commented Apr 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
discord-js ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 20, 2024 11:06pm
discord-js-guide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 20, 2024 11:06pm

@JMTK JMTK changed the title Prefer boolean client status comparison before activity checks perf(Presence): Prefer boolean client status comparison before activity checks Apr 14, 2024
@JMTK JMTK changed the title perf(Presence): Prefer boolean client status comparison before activity checks perf(Presence): prefer boolean client status comparison before activity checks Apr 14, 2024
@Jiralite Jiralite added this to the discord.js 14.15 milestone Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants