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

Fix option parsing #1229

Merged
merged 12 commits into from
Apr 5, 2022
Merged

Fix option parsing #1229

merged 12 commits into from
Apr 5, 2022

Conversation

BobDotCom
Copy link
Member

Summary

Fixes option parsing... why was it like this in the first place

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, typehinting, examples, ...)

@BobDotCom BobDotCom added this to the v2.0 milestone Apr 4, 2022
@BobDotCom BobDotCom self-assigned this Apr 4, 2022
Copy link
Contributor

@krittick krittick left a comment

Choose a reason for hiding this comment

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

We should be clearer in using variable names, and this method still keeps the line length under 120.

discord/commands/core.py Outdated Show resolved Hide resolved
discord/commands/core.py Outdated Show resolved Hide resolved
discord/commands/core.py Outdated Show resolved Hide resolved
discord/commands/core.py Outdated Show resolved Hide resolved
discord/commands/core.py Outdated Show resolved Hide resolved
discord/commands/core.py Outdated Show resolved Hide resolved
discord/commands/core.py Outdated Show resolved Hide resolved
discord/commands/core.py Outdated Show resolved Hide resolved
BobDotCom and others added 8 commits April 3, 2022 23:42
Co-authored-by: krittick <ben@krittick.net>
Co-authored-by: krittick <ben@krittick.net>
Co-authored-by: krittick <ben@krittick.net>
Co-authored-by: krittick <ben@krittick.net>
Co-authored-by: krittick <ben@krittick.net>
Co-authored-by: krittick <ben@krittick.net>
Co-authored-by: krittick <ben@krittick.net>
Co-authored-by: krittick <ben@krittick.net>
@BobDotCom
Copy link
Member Author

Rationale

The API sends resolved users (and other data types such as channels and roles) in the interaction data. This PR fixes option parsing to use that resolved data instead of using utils.get_or_fetch on the IDs passed.

Benchmarks

All times are relative times (i.e. they can be negative) but they are accurate when compared against each other.
Above red line: Before
Below red line: After
All benchmarks are run with the member intent disabled.

One user

In this benchmark we can see that the previous implementation slightly outperforms for the bots own user as it is always cached. The new implementation performs ~100-150ms faster for other users.

Screen Shot 2022-04-04 at 3 30 20 PM

Five users

In this benchmark the bot user performs very similarly, but other users pull ahead by up to one second (1000ms).

Screen Shot 2022-04-04 at 3 44 09 PM

@BobDotCom BobDotCom linked an issue Apr 5, 2022 that may be closed by this pull request
@BobDotCom BobDotCom marked this pull request as ready for review April 5, 2022 16:10
@BobDotCom BobDotCom enabled auto-merge (squash) April 5, 2022 16:10
@BobDotCom BobDotCom requested review from krittick and Dorukyum April 5, 2022 16:11
@Lulalaby Lulalaby disabled auto-merge April 5, 2022 18:52
@Lulalaby Lulalaby merged commit 409fe7a into master Apr 5, 2022
@Lulalaby Lulalaby deleted the fix-option-parsing branch April 5, 2022 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high High Priority status: in progress Work in Progess
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix parsing for discord.User type options
4 participants