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

Stop inlining display_width #335

Merged
merged 1 commit into from
May 3, 2021
Merged

Conversation

mgeisler
Copy link
Owner

@mgeisler mgeisler commented May 3, 2021

This removes the size of Textwrap drops from 16.3 KiB to 13.5 KiB as per cargo bloat on a simple “Hello World” program.

As far as I can measure, inlining display_width actually makes performance slightly worse. The benchmark results jump around a little, but we can plot them as a histogram. All numbers are microseconds for the fill_optimal_fit_ascii/4800 benchmark.

With the #[inline] attribute:

# Mean = 254.7
237 .. 240 [  1 ]: ∎
240 .. 243 [  1 ]: ∎
243 .. 246 [  0 ]:
246 .. 249 [  1 ]: ∎
249 .. 252 [  9 ]: ∎∎∎∎∎∎∎∎∎
252 .. 255 [  6 ]: ∎∎∎∎∎∎
255 .. 258 [ 15 ]: ∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
258 .. 261 [ 15 ]: ∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
261 .. 264 [  1 ]: ∎
264 .. 267 [  1 ]: ∎

Without the #[inline] attribute:

# Mean = 251.8
239 .. 241 [  1 ]: ∎
241 .. 243 [  1 ]: ∎
243 .. 245 [  4 ]: ∎∎∎∎
245 .. 247 [  4 ]: ∎∎∎∎
247 .. 249 [  2 ]: ∎∎
249 .. 251 [  7 ]: ∎∎∎∎∎∎∎
251 .. 253 [  9 ]: ∎∎∎∎∎∎∎∎∎
253 .. 255 [  3 ]: ∎∎∎
255 .. 257 [  7 ]: ∎∎∎∎∎∎∎
257 .. 259 [ 12 ]: ∎∎∎∎∎∎∎∎∎∎∎∎

As can be seen, the mean drops by 3 microseconds.

This removes the size of Textwrap drops from 16.3 KiB to 13.5 KiB as
per `cargo bloat` on a simple “Hello World” program.

As far as I can measure, inlining `display_width` actually makes
performance slightly worse. The benchmark results jump around a
little, but we can plot them as a histogram. All numbers are
microseconds for the `fill_optimal_fit_ascii/4800` benchmark.

With the `#[inline]` attribute:

    # Mean = 254.7
    237 .. 240 [  1 ]: ∎
    240 .. 243 [  1 ]: ∎
    243 .. 246 [  0 ]:
    246 .. 249 [  1 ]: ∎
    249 .. 252 [  9 ]: ∎∎∎∎∎∎∎∎∎
    252 .. 255 [  6 ]: ∎∎∎∎∎∎
    255 .. 258 [ 15 ]: ∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
    258 .. 261 [ 15 ]: ∎∎∎∎∎∎∎∎∎∎∎∎∎∎∎
    261 .. 264 [  1 ]: ∎
    264 .. 267 [  1 ]: ∎

Without the `#[inline]` attribute:

    # Mean = 251.8
    239 .. 241 [  1 ]: ∎
    241 .. 243 [  1 ]: ∎
    243 .. 245 [  4 ]: ∎∎∎∎
    245 .. 247 [  4 ]: ∎∎∎∎
    247 .. 249 [  2 ]: ∎∎
    249 .. 251 [  7 ]: ∎∎∎∎∎∎∎
    251 .. 253 [  9 ]: ∎∎∎∎∎∎∎∎∎
    253 .. 255 [  3 ]: ∎∎∎
    255 .. 257 [  7 ]: ∎∎∎∎∎∎∎
    257 .. 259 [ 12 ]: ∎∎∎∎∎∎∎∎∎∎∎∎

As can be seen, the mean drops by 3 microseconds.
@mgeisler mgeisler merged commit 0e4f3d0 into master May 3, 2021
@mgeisler mgeisler deleted the remove-display-width-inline branch May 3, 2021 18:36
This was referenced May 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant