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(Role): linear speed position getter #9493

Merged
merged 2 commits into from May 5, 2023

Conversation

kyranet
Copy link
Member

@kyranet kyranet commented May 1, 2023

Please describe the changes this PR makes and why it should be merged:

Alternative to #9490, fixes #3925.

Iterations Old New Difference
10_000 631.24ms 174.44ms 27.63%
100_000 8.01s 1.89s 23.59%

Basically skips the sorted call, which is an algorithm with an O(n * log(n)) cost, as well as the indexOf, which is a O(n) call. With this, not only it's not longer allocating a Collection nor an Array (making the only allocation be the iterator used in reduce), but the performance also goes down to a single O(n).

🤖 Generated by Copilot at 8b28bc4

position getter
improved with reduce function
snowflakes in winter

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@kyranet kyranet requested a review from a team as a code owner May 1, 2023 22:02
@vercel
Copy link

vercel bot commented May 1, 2023

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

Name Status Preview Comments Updated (UTC)
discord-js ❌ Failed (Inspect) May 5, 2023 0:45am
discord-js-guide ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2023 0:45am

@jaw0r3k
Copy link
Contributor

jaw0r3k commented May 1, 2023

Can you make the same for channels?

@kyranet
Copy link
Member Author

kyranet commented May 1, 2023

Yes, in a follow-up PR, I wanted to push this one first to get reviews in case the code can be improved any further.

@jaw0r3k
Copy link
Contributor

jaw0r3k commented May 1, 2023

Yes, in a follow-up PR, I wanted to push this one first to get reviews in case the code can be improved any further.

Idk if using for loop wont be a little bit faster, as it will be not calling the function everytime
Except that it looks good

Copy link
Member

@iCrawl iCrawl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐎

@github-actions
Copy link

github-actions bot commented May 5, 2023

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 39
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 94
🟠 PWA 70

Lighthouse ran on https://discord-js-guide-git-fork-kyranet-perf-rolefas-cb6b68-discordjs.vercel.app/guide/home/introduction

@kodiakhq kodiakhq bot merged commit 8e9a2b4 into discordjs:main May 5, 2023
5 of 6 checks passed
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.

Sorting members by highest role position takes extremely long in large servers (10k+ members)
6 participants