-
Notifications
You must be signed in to change notification settings - Fork 23
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
Fix deref #106
base: develop
Are you sure you want to change the base?
Fix deref #106
Conversation
Cool, thanks for the effort! Edit: I didn't see it's already marked as "Draft". I'm starting to try to understand your PR and I will probably have to come back to this later. As a reminder for myself and to help other reviewers, I summarize the PR here:
It's not clear to me yet how this solves the issue with the |
This is actually not so easy to understand, this require to well understand how works lifetimes inference/elision/binding, and how dereferentiations works and when it occur implicitly. Chapters 3.3 to 3.6 of the nomicon explain the lifetime part. Solving this issue at this step was even unintentional, I realized afterwards it was solved. For an explanations with an example: struct Amp {
foo: Option<&'static [f32]>
}
struct Ports { input: InputPort<Audio> }
impl Plugin for Amp {
fn run(&mut self, ports: &mut Ports, _features: &mut (), _: u32) {
self.foo.replace(&*ports.input); // Should fail to compile now because lifetime issue
}
}
Before the fix And keep in mind lifetimes issue aren't fully solved. Ports are just difficult to move away from run context, A safe legal way may exist. And this difficulty exist because i didn't implement Sync or Send for any ports. In Theory, it's may legal to implement those trait for some ports. |
Thanks for explaining. If I get it correctly, the important part is in the implementation of the
Because of the other changes, now I think
The only thing I could think about is that the Looks nice! I'm enthusiastic about this PR! |
Sharing port data across "scoped threads" is probably less efficient than copying port data across to a threads pool. Spawning/Joining threads have probably a much higher overhead than copying port data. And because of Multi-threading overheads in general, i don't think there is so many situation where multi-threading actually improve performance. I think If someone want to optimize by increasing parallelism, he should look first how to rewrite it's algorithm to increase auto-vectorisation. |
forgot to say, i'm not currently working on this PR. It's really difficult to understand how the Atom crate work internally. Things seems excessively complex. the "Deref missunderstanding" persisted here resulting to have Port that can't be easily fixed. I also found some suspicious code like a a lifetime transmutation. Maybe i shouldn't wait atom to be fixed to propose a PR reworking port system |
I already mentioned it elsewhere, few time ago i discovered that the port system and especially the dereferentiation mechanism was wrongly implemented, so i started to fix it. This fix would solve #95 and make ports safer. Every reference gotten from ports inside run context couldn't outlive this context. However, ports themself may moved out from run context, but i actually didn't find a way.
Current state:
EDIT: forgot to mention, a new issue appear with this fix, "inplace output" ports can produce mutable reference, which is bad. This is not addressed here because this require to modify some design choice about ports.