-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Improve twilight_mention::fmt
performance by ~10%
#942
Merged
zeylahellyer
merged 2 commits into
twilight-rs:main
from
zeylahellyer:refactor/mention/fmt/perf
Jun 19, 2021
Merged
Improve twilight_mention::fmt
performance by ~10%
#942
zeylahellyer
merged 2 commits into
twilight-rs:main
from
zeylahellyer:refactor/mention/fmt/perf
Jun 19, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Improve the performance of `twilight_mention::fmt` by around 10% by calling `Display::fmt` and `Formatter::write_str` directly instead of using `write!` and `format_args!`, which are notoriously[1][2] slow. Benchmarks: ``` format channel id time: [30.245 ns 30.317 ns 30.393 ns] change: [-9.1152% -8.6720% -8.2652%] (p = 0.00 < 0.05) Performance has improved. Found 2 outliers among 100 measurements (2.00%) 1 (1.00%) low mild 1 (1.00%) high mild format emoji id time: [31.604 ns 31.629 ns 31.658 ns] change: [-11.386% -10.974% -10.517%] (p = 0.00 < 0.05) Performance has improved. Found 8 outliers among 100 measurements (8.00%) 1 (1.00%) low severe 2 (2.00%) high mild 5 (5.00%) high severe format role id time: [31.130 ns 31.155 ns 31.186 ns] change: [-11.698% -11.386% -11.081%] (p = 0.00 < 0.05) Performance has improved. Found 8 outliers among 100 measurements (8.00%) 2 (2.00%) low severe 3 (3.00%) high mild 3 (3.00%) high severe format user id time: [29.444 ns 29.473 ns 29.507 ns] change: [-12.385% -12.045% -11.657%] (p = 0.00 < 0.05) Performance has improved. Found 16 outliers among 100 measurements (16.00%) 6 (6.00%) low severe 2 (2.00%) low mild 5 (5.00%) high mild 3 (3.00%) high severe ``` [1]: rust-lang/rust#76490 [2]: rust-lang/rust#10761 Signed-off-by: Vivian Hellyer <vivian@hellyer.dev>
zeylahellyer
added
c-mention
Affects the mention crate
t-refactor
Refactors APIs or code.
labels
Jun 18, 2021
3 tasks
Fails due to Rust 1.53 Clippy. #941 separately fixes them. |
Erk-
approved these changes
Jun 19, 2021
7596ff
approved these changes
Jun 19, 2021
zeylahellyer
added a commit
that referenced
this pull request
Jun 29, 2021
Instead of using the `write!` and `format_args!` macros use `Display` and `Formatter` method calls. The motivation for doing this is shown in PR #942. This does not include the work required to replace `write!` calls in `http/src/routing.rs`; this work will be done in a separate PR. Additionally one call is left in `http/src/request/channel/reaction/mod.rs` and will be resolved in another PR extracted from further work on #923. Relates to #943.
7596ff
pushed a commit
that referenced
this pull request
Jun 29, 2021
Instead of using the `write!` and `format_args!` macros use `Display` and `Formatter` method calls. The motivation for doing this is shown in PR #942. This does not include the work required to replace `write!` calls in `http/src/routing.rs`; this work will be done in a separate PR. Additionally one call is left in `http/src/request/channel/reaction/mod.rs` and will be resolved in another PR extracted from further work on #923. Relates to #943.
zeylahellyer
added a commit
that referenced
this pull request
Jul 2, 2021
Additions Support the new timestamp (`<t:unixtimestamp:?style>`) format via the new `timestamp` module by adding a formatter and parser implementation ([#945] - [@zeylahellyer]). Enhancements Improve the `Display` implementation performance of `ParseMentionError`'s `Display` implementation by calling `Formatter` methods directly instead of calling the `format_args!` and `write!` macros ([#944] - [@zeylahellyer]). Improve the performance of the `fmt` module's Display implementations by ~10% by directly writing to Formatters instead of calling the `format_args!` macro ([#942] - [@zeylahellyer]). [@zeylahellyer]: https://github.com/zeylahellyer [#945]: #945 [#944]: #944 [#942]: #942 Signed-off-by: Zeyla Hellyer <zeyla@hellyer.dev>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improve the performance of
twilight_mention::fmt
by around 10% by callingDisplay::fmt
andFormatter::write_str
directly instead of usingwrite!
andformat_args!
, which are notoriously (1, 2) slow.Benchmarks: