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

rayon adaptive #616

Open
wagnerf42 opened this issue Dec 21, 2018 · 5 comments
Open

rayon adaptive #616

wagnerf42 opened this issue Dec 21, 2018 · 5 comments

Comments

@wagnerf42
Copy link
Contributor

hi everyone,

you are all moving fast and i'm moving slowly but finally I wanted to present my work on rayon.

the idea has been to implement several techniques from our lab on top of rayon.

i've written a serie of blog posts here:
http://www-id.imag.fr/Laboratoire/Membres/Wagner_Frederic/rayon-adaptive.html

I don't present all my work but it is already a big chunk of it.
I would be very happy to discuss with everyone about it.

I hope you have some time during the holidays :-)

all feedback is welcome. thanks again for your wonderful library

@nikomatsakis
Copy link
Member

Very cool! I am excited to read more deeply into those posts!

@wagnerf42
Copy link
Contributor Author

hi niko,
I hope it will be interesting. there is more to come but i'm again a bit overwhelmed right now.

@cuviper
Copy link
Member

cuviper commented Jun 29, 2019

Take note of #666, where a user is concerned about allocation overhead. In our last discussion, we were talking about Clone / Arc for your map closures -- both solutions may invoke the allocator in places where we don't now.

@wagnerf42
Copy link
Contributor Author

wagnerf42 commented Jun 29, 2019 via email

@cuviper
Copy link
Member

cuviper commented Jul 1, 2019

maybe I don't really get what's a closure.

This post may help you:
https://krishnasannasi.github.io/rust/syntactic/sugar/2019/01/17/Closures-Magic-Functions.html

A closure is basically just a struct of the captured variables. If there are no captures at all, the closure will have zero size, not even a code pointer -- the code is statically known for a given closure type.

if I clone a closure isn't it just a pointer copy ?

For an immediate closure value, you're cloning the struct of captures -- which could just be references, but not necessarily. Cloning a reference &F where F: Fn is just a pointer copy though. Cloning a trait object like &dyn Fn would also be just a pointer copy -- actually a "fat" pointer pair of the struct pointer and a vtable pointer.

also, do you have an example of some closure which implements Fn but not Clone ?

By default, a Fn will only capture things by shared reference (&), and that trivially implements Clone, even Copy. However, this implies a lifetime on the closure for those references, which you sometimes want to avoid -- then you would use the move keyword on the closure. Then the closure will actually contain direct values owned in its struct, even though calling the closure still only has shared access through &self. These values may be expensive to clone (e.g. a large Vec as a lookup table), or might not implement Clone at all (e.g. a File).

finally, if someone gives a reference to a closure as argument will not the clone happen on the reference then ?

Yes, as &Fn also implements Fn, and then this is trivially both Clone and Copy. But note that your returned iterator like Map is now tied to the lifetime of that closure you referenced.

It's definitely a breaking change to add a Clone constraint where we currently accept Fn, and it would also make some move use cases impossible.


Adding Arc internally is a simpler solution, but introduces an allocation as noted.

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

No branches or pull requests

3 participants