- 
                Notifications
    You must be signed in to change notification settings 
- Fork 76
Optimize out allocations as much as possible #27
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
Conversation
| I don't understand where the double boxing is supposed to be.  I'm also not clear on what justifies the extra complexity of that new enum. If anything, it seems it adds an extra lookup/branching for each call to the  | 
| The double boxing happens in something like this where boxing is needed to create homogeneous types:     let seq2 = Sequence::new([
        Box::new(tween_move) as Box<dyn Tweenable<Transform> + Send + Sync + 'static>,
        Box::new(tracks) as Box<dyn Tweenable<Transform> + Send + Sync + 'static>,
    ]);That's an array of boxes which get boxed again because of  | 
| 
 Ok, so it seems that adding a constructor for an already-boxed collection solves the issue, no? fn from_vec(v: Vec<Box<dyn Tweenable<T> + Send + Sync + 'static>>) -> Self;Or alternatively maybe some  The  See #28 for a draft of what that looks like with the  Note that double-boxing seems to be a tough issue with many crates and the language itself having issues with it. Just searching for double boxing returns 4 related GitHub items just for futures (rust-lang/futures-rs#228. rust-lang/futures-rs#511, rust-lang/futures-rs#512, rust-lang/futures-rs#513). They're all closed in favor of using the upcoming trait specialization, which was discussed on those issues as being the correct way to fix this (but is not in stable yet). | 
| Yeah, I was hoping to avoid adding new methods since I don't think people will know why they are different and ideally we'll use specialization once it comes out. The other bummer with adding a from_vec method is that it prevents us from doing something like using a smallvec inside the sequence + Tracks (which would make sense if we keep a vec of boxes since those are only 16 bytes). If you're on board with avoiding the double boxing but not the other stuff, I can continue fiddling around with the into iterator method to get just the double boxing avoidance. | 
| 
 Yes, the double boxing should be avoided if possible, while I'm not too warm at the idea of the enum for manual dynamic dispatch, so if possible I'd rather separate those. If you have a better way to prevent the double-boxing I'm all for it; I couldn't find one, and if the folks from  | 
| This shouldn't double box because into on self just returns self: // From implies Into
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
impl<T, U> const Into<U> for T
where
    U: ~const From<T>,
{
    /// Calls `U::from(self)`.
    ///
    /// That is, this conversion is whatever the implementation of
    /// <code>[From]<T> for U</code> chooses to do.
    fn into(self) -> U {
        U::from(self)
    }
}
// From (and thus Into) is reflexive
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "88674")]
impl<T> const From<T> for T {
    /// Returns the argument unchanged.
    fn from(t: T) -> T {
        t
    }
} | 
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment on .into() instead of direct Box::new() use, and missing CHANGELOG. After that looks good.
Co-authored-by: Jerome Humbert <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
…nted for all tweenables without specialization Signed-off-by: Alex Saveau <[email protected]>
| Done! | 
Fix double-boxing by removing the `IntoBoxDynTweenable` trait and the impl of `Tweenable<T>` for `Box<dyn Tweenable>`, and instead using some `From` conversion implemented per concrete type.
Current paint points:
IntoBoxDynTweenableunconditionally boxes and there's no way to avoid this without specialization which is a long ways away).Solutions:
This makes built-ins zero cost while 3P types only suffer one layer of indirection.
Closes #28