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

Compress Liveness data some more. #54420

Merged
merged 1 commit into from
Sep 22, 2018
Merged

Conversation

nnethercote
Copy link
Contributor

Profiling shows that the (reader, writer, used) triples used by
liveness analysis almost always have invalid reader and writer
fields. We can take advantage of this knowledge to use a compressed
representation for them, falling back to a secondary table for the
uncommon cases.

This change reduces instruction counts on numerous benchmarks, the best
by 16%. It also reduces max-rss on numerous benchmarks, the best by 38%.

The patch also renames these triples from Users to RWU, because it's
confusing having a type whose name is plural and then used within
vectors whose names are also plural.

r? @nikomatsakis

Profiling shows that the `(reader, writer, used)` triples used by
liveness analysis almost always have invalid `reader` and `writer`
fields. We can take advantage of this knowledge to use a compressed
representation for them, falling back to a secondary table for the
uncommon cases.

This change reduces instruction counts on numerous benchmarks, the best
by 16%. It also reduces max-rss on numerous benchmarks, the best by 38%.

The patch also renames these triples from `Users` to `RWU`, because it's
confusing having a type whose name is plural and then used within
vectors whose names are also plural.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 21, 2018
@nnethercote
Copy link
Contributor Author

I know I just changed this code in #54211, but I came up with this better way of handling things and couldn't resist trying. It worked better than I expected. Instruction counts:

keccak-check
        avg: -5.0%      min: -16.2%     max: -1.2%
keccak-debug
        avg: -6.1%      min: -14.0%     max: -1.5%
keccak-opt
        avg: -5.5%      min: -14.0%     max: -1.2%
inflate-check
        avg: -2.4%      min: -8.3%      max: -0.9%
inflate-opt
        avg: -2.0%?     min: -6.8%?     max: -0.3%?
inflate-debug
        avg: -2.6%      min: -6.4%      max: -1.3%
clap-rs-check
        avg: -2.4%      min: -4.7%      max: -0.8%
clap-rs-debug
        avg: -2.6%      min: -3.7%      max: -2.0%
clap-rs-opt
        avg: -1.5%      min: -2.5%      max: -1.0%

max-rss:

keccak-check
        avg: -27.4%     min: -38.7%     max: -0.1%
keccak-debug
        avg: -12.7%     min: -38.0%     max: 0.0%
keccak-opt
        avg: -12.7%     min: -38.0%     max: 0.0%
inflate-check
        avg: -6.2%      min: -18.4%     max: 0.2%
inflate-opt
        avg: -2.1%?     min: -9.3%?     max: 0.6%?
inflate-debug
        avg: -1.6%      min: -8.8%      max: 1.6%
clap-rs-debug
        avg: 1.6%       min: -0.6%      max: 7.2%
clap-rs-opt
        avg: -1.4%      min: -6.6%      max: 0.8%
clap-rs-check
        avg: -0.6%      min: -0.9%      max: -0.1%

I also tried a different representation, where each packed RWU was a single byte and the secondary table was an FxHashMap. It saved some more memory, but the instruction counts and wall-times were a bit higher, so I finalized on this vector approach.

@nnethercote
Copy link
Contributor Author

@bors try

@bors
Copy link
Contributor

bors commented Sep 21, 2018

⌛ Trying commit b2f25e3 with merge b77797424ed915239023046f4894ca3d3f60d2c3...

@nnethercote
Copy link
Contributor Author

BTW, although the benefits (esp. max-rss) mostly accrue to non-NLL builds, the NLL builds do get some improvement.

@bors
Copy link
Contributor

bors commented Sep 21, 2018

☀️ Test successful - status-travis
State: approved= try=True

@nikomatsakis
Copy link
Contributor

@bors r+

@nnethercote what do you think about trying to rewrite this pass altogether to operate on MIR? By this point you've about rewritten it already a few times. =)

@bors
Copy link
Contributor

bors commented Sep 21, 2018

📌 Commit b2f25e3 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 21, 2018
@nnethercote
Copy link
Contributor Author

LOL, I could give it a try, though you said previously that @wesleywiser was interested and I wouldn't want to steal it from them.

@wesleywiser
Copy link
Member

wesleywiser commented Sep 21, 2018

@nnethercote Please, feel free to take that :) I've got a couple other things on my plate at the moment. I'll get to it at some point if you don't.

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Sep 22, 2018
…tsakis

Compress `Liveness` data some more.

Profiling shows that the `(reader, writer, used)` triples used by
liveness analysis almost always have invalid `reader` and `writer`
fields. We can take advantage of this knowledge to use a compressed
representation for them, falling back to a secondary table for the
uncommon cases.

This change reduces instruction counts on numerous benchmarks, the best
by 16%. It also reduces max-rss on numerous benchmarks, the best by 38%.

The patch also renames these triples from `Users` to `RWU`, because it's
confusing having a type whose name is plural and then used within
vectors whose names are also plural.

r? @nikomatsakis
bors added a commit that referenced this pull request Sep 22, 2018
Rollup of 16 pull requests

Successful merges:

 - #53652 (define copy_within on slices)
 - #54261 (Make `dyn` a keyword in the 2018 edition)
 - #54280 (remove (more) CAS API from Atomic* types where not natively supported)
 - #54323 (rustbuild: drop color handling)
 - #54350 (Support specifying edition in doc test)
 - #54370 (Improve handling of type bounds in `bit_set.rs`.)
 - #54371 (add -Zui-testing to rustdoc)
 - #54374 (Make 'proc_macro::MultiSpan' public.)
 - #54402 (Use no_default_libraries for all NetBSD flavors)
 - #54409 (Detect `for _ in in bar {}` typo)
 - #54412 (add applicability to span_suggestion call)
 - #54413 (Add UI test for deref recursion limit printing twice)
 - #54415 (parser: Tweak function parameter parsing to avoid rollback on succesfull path)
 - #54420 (Compress `Liveness` data some more.)
 - #54422 (Simplify slice's first(_mut) and last(_mut) with get)
 - #54446 (Unify christianpoveda's emails)

Failed merges:

 - #54058 (Introduce the partition_dedup/by/by_key methods for slices)

r? @ghost
bors added a commit that referenced this pull request Sep 22, 2018
Rollup of 16 pull requests

Successful merges:

 - #53652 (define copy_within on slices)
 - #54261 (Make `dyn` a keyword in the 2018 edition)
 - #54280 (remove (more) CAS API from Atomic* types where not natively supported)
 - #54323 (rustbuild: drop color handling)
 - #54350 (Support specifying edition in doc test)
 - #54370 (Improve handling of type bounds in `bit_set.rs`.)
 - #54371 (add -Zui-testing to rustdoc)
 - #54374 (Make 'proc_macro::MultiSpan' public.)
 - #54402 (Use no_default_libraries for all NetBSD flavors)
 - #54409 (Detect `for _ in in bar {}` typo)
 - #54412 (add applicability to span_suggestion call)
 - #54413 (Add UI test for deref recursion limit printing twice)
 - #54415 (parser: Tweak function parameter parsing to avoid rollback on succesfull path)
 - #54420 (Compress `Liveness` data some more.)
 - #54422 (Simplify slice's first(_mut) and last(_mut) with get)
 - #54446 (Unify christianpoveda's emails)

Failed merges:

 - #54058 (Introduce the partition_dedup/by/by_key methods for slices)

r? @ghost
@bors bors merged commit b2f25e3 into rust-lang:master Sep 22, 2018
@nnethercote nnethercote deleted the PackedRWU-Vec branch September 23, 2018 20:54
@nnethercote
Copy link
Contributor Author

Perf results look good, as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants