Optimize formatting by 80-90% by avoiding write!. #303

Merged
huonw merged 2 commits from string-formatting into master 2018-08-23 01:48:43 -05:00
huonw commented 2018-08-23 00:58:11 -05:00 (Migrated from github.com)

I'm submitting a(n) refactor.

Description

Using a temporary byte buffer along with manual decomposition of the
UUID means the code compiles down to a nice loop, instead of doing
multiple virtual function calls as it does with write!.

Motivation

The code was unnecessarily slow.

Tests

All the existing formatting tests pass, and I introduced a benchmark. Here's the output of cargo benchcmp on before/after results for that benchmark:

name          before.txt ns/iter  after.txt ns/iter  diff ns/iter   diff %  speedup
bench_hyphen  270                 49                         -221  -81.85%   x 5.51
bench_simple  418                 40                         -378  -90.43%  x 10.45
bench_urn     281                 56                         -225  -80.07%   x 5.02
**I'm submitting a(n)** refactor. # Description Using a temporary byte buffer along with manual decomposition of the UUID means the code compiles down to a nice loop, instead of doing multiple virtual function calls as it does with `write!`. # Motivation The code was unnecessarily slow. # Tests All the existing formatting tests pass, and I introduced a benchmark. Here's the output of `cargo benchcmp` on before/after results for that benchmark: name before.txt ns/iter after.txt ns/iter diff ns/iter diff % speedup bench_hyphen 270 49 -221 -81.85% x 5.51 bench_simple 418 40 -378 -90.43% x 10.45 bench_urn 281 56 -225 -80.07% x 5.02
radix (Migrated from github.com) reviewed 2018-08-23 00:58:11 -05:00
Dylan-DPC-zz (Migrated from github.com) reviewed 2018-08-23 00:58:11 -05:00
kinggoesgaming (Migrated from github.com) reviewed 2018-08-23 00:58:11 -05:00
KodrAus commented 2018-08-23 01:42:25 -05:00 (Migrated from github.com)

Looks good to me! Thanks @huonw

bors r+

Looks good to me! Thanks @huonw bors r+
KodrAus (Migrated from github.com) approved these changes 2018-08-23 01:44:11 -05:00
bors[bot] commented 2018-08-23 01:48:42 -05:00 (Migrated from github.com)
# Build succeeded * [continuous-integration/travis-ci/push](https://travis-ci.org/uuid-rs/uuid/builds/419512259?utm_source=github_status&utm_medium=notification) * [continuous-integration/appveyor/branch](https://ci.appveyor.com/project/KodrAus/uuid/build/1.0.889)
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-uuid-rs/uuid!303
No description provided.