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

Use smaller discriminants for generators #69837

Merged
merged 3 commits into from
Mar 19, 2020
Merged

Use smaller discriminants for generators #69837

merged 3 commits into from
Mar 19, 2020

Conversation

jonas-schievink
Copy link
Contributor

@jonas-schievink jonas-schievink commented Mar 8, 2020

Closes #69815

I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on)

  • Add test with a generator that has exactly 256 total states
  • Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant
  • Add tests for the size of Option<[generator]>
  • Add tests for the discriminant_value intrinsic in all cases

@rust-highfive
Copy link
Collaborator

r? @ecstatic-morse

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 8, 2020
@jonas-schievink
Copy link
Contributor Author

jonas-schievink commented Mar 8, 2020

Running this on async-std's mutex.rs bench shows some unfortunate regressions that I compared the wrong compilers, there are no significant perf regressions on this benchmark (it got a bit faster, even):

master:

test contention    ... bench:   1,028,149 ns/iter (+/- 42,225)
test create        ... bench:           3 ns/iter (+/- 0)
test no_contention ... bench:     954,627 ns/iter (+/- 30,982)

This PR

test contention    ... bench:   1,025,108 ns/iter (+/- 87,055)
test create        ... bench:           3 ns/iter (+/- 0)
test no_contention ... bench:     886,630 ns/iter (+/- 24,225)

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Mar 9, 2020

Nice! I don't have the requisite understanding of generators to approve this, so...

r? @tmandry

@ecstatic-morse

This comment has been minimized.

Comment on lines +89 to +95
assert_eq!(3, std::mem::size_of_val(&await1_level1()));
assert_eq!(4, std::mem::size_of_val(&await2_level1()));
assert_eq!(5, std::mem::size_of_val(&await3_level1()));
assert_eq!(8, std::mem::size_of_val(&await3_level2()));
assert_eq!(11, std::mem::size_of_val(&await3_level3()));
assert_eq!(14, std::mem::size_of_val(&await3_level4()));
assert_eq!(17, std::mem::size_of_val(&await3_level5()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

much, much better :D

Comment on lines +123 to +133
assert_eq!(size_of_val(&gen_u8_tiny_niche()), 1);
assert_eq!(size_of_val(&Some(gen_u8_tiny_niche())), 1); // uses niche
assert_eq!(size_of_val(&Some(Some(gen_u8_tiny_niche()))), 2); // cannot use niche anymore
assert_eq!(size_of_val(&gen_u8_full()), 1);
assert_eq!(size_of_val(&Some(gen_u8_full())), 2); // cannot use niche
assert_eq!(size_of_val(&gen_u16()), 2);
assert_eq!(size_of_val(&Some(gen_u16())), 2); // uses niche

cycle(gen_u8_tiny_niche(), 254);
cycle(gen_u8_full(), 255);
cycle(gen_u16(), 256);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test. The discriminant checks are dependent on implementation details of the meaning of each value, but that's fine - we can update the test if those change.

@tmandry
Copy link
Member

tmandry commented Mar 10, 2020

Looks great, thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Mar 10, 2020

📌 Commit b16d659 has been approved by tmandry

@bors
Copy link
Contributor

bors commented Mar 10, 2020

🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened

@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 Mar 10, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 10, 2020
…andry

Use smaller discriminants for generators

Closes rust-lang#69815

I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on)

* [x] Add test with a generator that has exactly 256 total states
* [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant
* [x] Add tests for the size of `Option<[generator]>`
* [x] Add tests for the `discriminant_value` intrinsic in all cases
Centril added a commit to Centril/rust that referenced this pull request Mar 10, 2020
…andry

Use smaller discriminants for generators

Closes rust-lang#69815

I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on)

* [x] Add test with a generator that has exactly 256 total states
* [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant
* [x] Add tests for the size of `Option<[generator]>`
* [x] Add tests for the `discriminant_value` intrinsic in all cases
bors added a commit that referenced this pull request Mar 10, 2020
Rollup of 6 pull requests

Successful merges:

 - #69122 (Backtrace Debug tweaks)
 - #69591 (Use TypeRelating for instantiating query responses)
 - #69760 (Improve expression & attribute parsing)
 - #69837 (Use smaller discriminants for generators)
 - #69838 (Expansion-driven outline module parsing)
 - #69859 (fix #62456)

Failed merges:

r? @ghost
@jonas-schievink
Copy link
Contributor Author

Fixed size assertions after merge of #69716

@bors r=tmandry

@bors
Copy link
Contributor

bors commented Mar 14, 2020

📌 Commit 49aabd8 has been approved by tmandry

Centril added a commit to Centril/rust that referenced this pull request Mar 18, 2020
…andry

Use smaller discriminants for generators

Closes rust-lang#69815

I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on)

* [x] Add test with a generator that has exactly 256 total states
* [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant
* [x] Add tests for the size of `Option<[generator]>`
* [x] Add tests for the `discriminant_value` intrinsic in all cases
Centril added a commit to Centril/rust that referenced this pull request Mar 18, 2020
…andry

Use smaller discriminants for generators

Closes rust-lang#69815

I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on)

* [x] Add test with a generator that has exactly 256 total states
* [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant
* [x] Add tests for the size of `Option<[generator]>`
* [x] Add tests for the `discriminant_value` intrinsic in all cases
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Mar 18, 2020
Rollup of 10 pull requests

Successful merges:

 - rust-lang#67749 (keyword docs for else and inkeyword docs for else and in.)
 - rust-lang#69139 (clean up E0308 explanation)
 - rust-lang#69189 (Erase regions in writeback)
 - rust-lang#69837 (Use smaller discriminants for generators)
 - rust-lang#69838 (Expansion-driven outline module parsing)
 - rust-lang#69839 (Miri error reform)
 - rust-lang#69899 (Make methods declared by `newtype_index` macro `const`)
 - rust-lang#69920 (Remove some imports to the rustc crate)
 - rust-lang#70075 (Fix repr pretty display)
 - rust-lang#70106 (Tidy: fix running rustfmt twice)

Failed merges:

 - rust-lang#70051 (Allow `hir().find` to return `None`)
 - rust-lang#70074 (Expand: nix all fatal errors)

r? @ghost
@bors bors merged commit 4118ff6 into rust-lang:master Mar 19, 2020
Nemo157 added a commit to rust-lang/futures-rs that referenced this pull request Apr 7, 2020
@@ -23,6 +23,6 @@ fn main() {

// Neither of these generators have the resume arg live across the `yield`, so they should be
// 4 Bytes in size (only storing the discriminant)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonas-schievink Looks like you forgot to update the comment here.

@jonas-schievink jonas-schievink deleted the gen-discr-opt branch May 27, 2020 19:39
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 29, 2020
…r=nikomatsakis

Fix incorrect comment in generator test

rust-lang#69837 (comment) (thanks for the catch, @jplatte)
exrook pushed a commit to exrook/futures-rs that referenced this pull request Apr 5, 2021
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.

Generators should use smaller discriminants
6 participants