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(model/gateway)!: Optimize Event size #1436

Merged
merged 11 commits into from
Feb 11, 2022
Merged

perf(model/gateway)!: Optimize Event size #1436

merged 11 commits into from
Feb 11, 2022

Conversation

vilgotf
Copy link
Member

@vilgotf vilgotf commented Jan 11, 2022

  • chore(model/gateway): assert Event and variant sizes
  • refactor(model/gateway)!: Box large Event variants
  • refactor(model/gateway)!: Unbox small Event variants
  • refactor(model/gateway)!: Remove box From<DispatchEvent>

@github-actions github-actions bot added c-cache Affects the cache crate c-model Affects the model crate c-standby Affects the standby crate m-breaking change Breaks the public API. t-refactor Refactors APIs or code. labels Jan 11, 2022
@7596ff
Copy link
Contributor

7596ff commented Jan 14, 2022

Could you decide on and document a rule for when we should box events, should future ones be added?

@vilgotf
Copy link
Member Author

vilgotf commented Jan 15, 2022

Could you decide on and document a rule for when we should box events, should future ones be added?

In this PR I just boxed every variant larger than the already boxed ones and unboxed the ones smaller than Event. The optimal size of Event depends on the frequency of events, something where larger bots may see a different pattern compared to smaller ones.

I've not benchmarked before, nor can I create an accurate model of incoming Events, so I'll leave it to someone more experienced.

@vilgotf vilgotf changed the title refactor(model/gateway)!: Optimize Event size perf(model/gateway)!: Optimize Event size Jan 16, 2022
@github-actions github-actions bot added the t-perf Improves performace label Jan 16, 2022
model/src/gateway/event/mod.rs Show resolved Hide resolved
model/src/gateway/event/mod.rs Outdated Show resolved Hide resolved
@7596ff 7596ff self-assigned this Feb 10, 2022
* zeylahellyer: `dead_code` justification
* zeylahellyer: module level comment with instructions
@zeylahellyer
Copy link
Member

@7596ff I added the instructions I was talking about and probably didn't break CI.

@7596ff 7596ff removed the t-refactor Refactors APIs or code. label Feb 11, 2022
@7596ff 7596ff merged commit 100a501 into twilight-rs:next Feb 11, 2022
@vilgotf vilgotf deleted the refactor/model/gateway-event branch February 11, 2022 17:02
7596ff added a commit that referenced this pull request Mar 10, 2022
Channels

The `Channel` type has been unified into a struct ([#1449] -
[@zeylahellyer], [@itohatweb]). All possible fields of every channel
variant and thread variant are now present on this type. This change was
prompted by Discord's own storage of channels, and that variants do not
necessarily have guaranteed fields. See the PR description for more
details.

New `http` module

Add a new module, `http` ([#1508], [#1521] - [@7596ff]). This module
contains types that are only sent to Discord.

`AttachmentFile` has been moved from `twilight-http` and renamed to
`model::http::attachment::Attachment`.

`InteractionResponse` has been moved to
`model::http::interaction::InteractionResponse`. `CallbackData` has been
renamed to `InteractionResponseData`.

`PermissionOverwrite` now has a separate type in `model::http`; it
differs from a received `PermissionOverwrite` in that its `allow` and
`deny` fields are optional.

Additions

Add support for modals ([#1300] - [@itohatweb], [@7596ff]):
- Sending
  - add a new component, `TextInput`
  - move `Component` de/serialization to the enum itself, and remove all
    de/serialization from its variants
- Receiving
  - add `Interaction::Modal`, `InteractionType::ModalSubmit`
  - add `ModalSubmitInteraction`, `ModalInteractionData`,
    `ModalInteractionDataActionRow`, `ModalInteractionDataComponent`

Add `GuildStickersUpdate` to the `Event` enum ([#1520] - [@HTG-YT]).

Changes

`Event` variants have been boxed or unboxed based on a new threshold,
making the size of the enum more consistent ([#1436] - [@vilgotf]).

Rename `Intents::GUILD_EMOJIS` to `GUILD_EMOJIS_AND_STICKERS` ([#1520] -
[@HTG-YT]).

`PermissionOverwrite` has been refactored to more closely represent
Discord's model ([#1521] - [@7596ff]). Its ID is stored with a generic
marker, and can be casted to a member or role ID as needed.

Update to Discord API version 10 ([#1540] - [@zeylahellyer]). This
involves two changes:
- remove `CurrentApplicationInfo`'s `summary` field
- add `Intents::MESSAGE_CONTENT`

[#1300]: #1300
[#1436]: #1436
[#1449]: #1449
[#1508]: #1508
[#1520]: #1520
[#1521]: #1521
[#1540]: #1540

[@7596ff]: https://github.com/7596ff
[@HTG-YT]: https://github.com/HTG-YT
[@itohatweb]: https://github.com/itohatweb
[@vilgotf]: https://github.com/vilgotf
[@zeylahellyer]: https://github.com/zeylahellyer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-cache Affects the cache crate c-model Affects the model crate c-standby Affects the standby crate m-breaking change Breaks the public API. t-perf Improves performace
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants