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

homepage, bench improvement and doc fix #317

Merged
merged 5 commits into from
Mar 21, 2018
Merged

Conversation

dhardy
Copy link
Member

@dhardy dhardy commented Mar 20, 2018

No description provided.

@dhardy dhardy requested a review from pitdicker March 20, 2018 15:45
}
black_box(accum);
Copy link
Contributor

Choose a reason for hiding this comment

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

I had on my wish-list to investigate the benchmark 'problems'. So nice to see 😄. I also noticed some change if you set b.bytes before b.iter. Is that something you can confirm?

Copy link
Member Author

Choose a reason for hiding this comment

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

Never tried that.

Something similar might be possible for the fill_bytes stuff, but it's probably less significant (already this has little impact on 64-bit outputs).

Copy link
Contributor

Choose a reason for hiding this comment

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

It made a difference, but not any more with the accumulator.

@pitdicker
Copy link
Contributor

I would like to take a closer look, that will probably be tomorrow.

@dhardy
Copy link
Member Author

dhardy commented Mar 20, 2018

Added a bit more doc. I hope it's not too scary 😱

At this point maybe it's not worth mentioning the <R: Rng>(rng: R) variant at all actually; I tried implementing it but had some issues; see also #287 (comment)

@pitdicker
Copy link
Contributor

Your change really helps with the new parallel codegen. The same would be necessary for the distributions code. I gave it a try in https://github.com/pitdicker/rand/commits/doc_bench. Do you want to take that commit, or maybe do the same in some cleaner way?

Then there is only one test left that is badly affected by parallel codegen: misc_sample_indices_10_of_1k. I don't see an easy solution there yet.

@@ -6,7 +6,7 @@ license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-lang-nursery/rand"
documentation = "https://docs.rs/rand"
homepage = "https://github.com/rust-lang-nursery/rand"
homepage = "https://crates.io/crates/rand"
Copy link
Contributor

@pitdicker pitdicker Mar 21, 2018

Choose a reason for hiding this comment

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

I don't like either 😄. Every time I look up a crate on crates.io is surprisingly unhelpful, and I quickly click through to the repository or docs.rs.

But this seems like a good change.

@@ -4,9 +4,9 @@ version = "0.1.0-pre.0"
authors = ["The Rust Project Developers"]
license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-lang-nursery/rand"
repository = "https://github.com/rust-lang-nursery/rand/tree/master/rand-core"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is right, as you can't do git checkout https://github.com/rust-lang-nursery/rand/tree/master/rand-core. This should just be the base repository, and cargo figures things out.

@@ -4,9 +4,9 @@ version = "0.1.0-pre.0"
authors = ["The Rust Project Developers"]
license = "MIT/Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-lang-nursery/rand"
repository = "https://github.com/rust-lang-nursery/rand/tree/master/rand-core"
documentation = "https://docs.rs/rand"
Copy link
Contributor

@pitdicker pitdicker Mar 21, 2018

Choose a reason for hiding this comment

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

Does this line need changing?
(documentation = "https://docs.rs/rand")

src/lib.rs Outdated
/// `(&mut rng).gen()`, (3) in some cases `mut rng: R` is required, and (4)
/// since `R` may not be a reference (it has no reborrow requirement) and no
/// `Copy` bound, there is no choice but to move or double-reference uses of
/// `rng: R` within `foo`. Both 2 and 3 are probably Rust bugs, but 4 isn't
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a sentence of 12 lines. Do you happen to be a lawyer? 😄

src/lib.rs Outdated
/// - `fn foo<R: Rng>(rng: &mut R)` will not match type-erased `Rng`s; in order
/// to support dynamic dispatch use either
/// `fn foo<R: Rng + ?Sized>(rng: &mut R)` or `fn foo<R: Rng>(rng: R)`
/// (but see next point about the latter).
Copy link
Contributor

Choose a reason for hiding this comment

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

Added a bit more doc. I hope it's not too scary 😱

You give the technical reasons, and that is supposed to be a plus for programmers. But maybe it is good to help users a little. Maybe add something like:

Tip if you want to use Rng in trait bounds:
The basic pattern is fn foo<R: Rng + ?Sized>(rng: &mut R).

This way implementations can use the methods from both RngCore and Rng, support dynamic dispatch (thanks to ?Sized), and ...

Technical details:
...

let mut accum: $ty = 0;
for _ in 0..::RAND_BENCH_N {
accum = accum.wrapping_add(rng.gen_range($low, high));
high += fake_increment;
high += $incr; // force recalculation of range each time
Copy link
Contributor

Choose a reason for hiding this comment

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

How about high = high.wrapping_add(1) & std::%ty::MAX, so it also works for i8? (Not thought deeply about it to be honest)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that would still wrap, and end up less than low? Current version seems to work anyway.

@dhardy
Copy link
Member Author

dhardy commented Mar 21, 2018

I removed the generic usage doc (still working on that stuff). Rest is okay to merge?

@pitdicker
Copy link
Contributor

Yes. What did you think of #317 (comment)?

@dhardy
Copy link
Member Author

dhardy commented Mar 21, 2018

Didn't you see my reply?

@pitdicker
Copy link
Contributor

Sorry. I was comparing the benchmarks with and without parallel codegen, and checking the generated assembly on master, your branch, and my suggestion with a mask.

But without the mask, all the range code is completely optimized out, at least for i8. I don't completely get why. I pushed a commit the the same branch as before.

@dhardy
Copy link
Member Author

dhardy commented Mar 21, 2018

Ah, i8 is signed; took me a while to understand why binary and worked. 👍

@dhardy dhardy added P-high Priority: high D-review Do: needs review labels Mar 21, 2018
@pitdicker pitdicker merged commit 4634912 into rust-random:master Mar 21, 2018
@dhardy dhardy deleted the doc branch March 23, 2018 17:51
pitdicker added a commit that referenced this pull request Apr 4, 2018
homepage, bench improvement and doc fix
@pitdicker pitdicker mentioned this pull request May 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D-review Do: needs review P-high Priority: high
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants