-
Notifications
You must be signed in to change notification settings - Fork 18
Tiny Box optimization #20
Comments
Would it be possible to implement
This seems like it might be pretty important, since otherwise it wouldn't be possible to create a Also, what does the |
Yes. It depends upon
I donno enough about this. We discussed alloc-based gates for
I missspoke.. We'd need
In my mind, the I probably need to take some time to do a better PoC and then we can more meaningfully discuss how it should align with everything else. Of course, this is very much going the opposite direction from most of the goals of this group, but if we could make this work along side those, then we'd probably make everyone pretty happy.. well except folk who want to worry about fat pointer stability. ;) |
ooh well the good news is I'm already working on this issue as part of moving
Sounds good.
I don't really feel like this is going against the goals of the group, though the tie in to error handling is a little tenuous. Either way we're happy to help with brainstorming and providing feedback. If you're interested you should definitely attend our biweekly meetings and give status updates on your progress here. |
Does the TinyBox are part of rust core library? |
It does not exist yet, but it should only require the |
Good to hear if it's finally to be implemented in rust core |
I'll note |
It'd help nostd crates if..
There was a
TinyBox<T: Sized>
type with two functions:T
inside its data pointer ifsize_of::<T>() <= size_of::<usize>()
andalign_of::<T>() <= align_of::<usize>()
but otherwise acts likeBox
by using the pointer for an allocation if alloc exists, or panics if alloc does not exist.size_of_val(self) <= size_of::<usize>()
andalign_of_val(self) <= align_of::<usize>()
.In this way,
TinyBox<dyn Trait>
should works fine without alloc, provided the original typeT
occupies less thansize_of::<usize>()
bytes.Afaik, we do not need rustc modification or std support for this because rustc already requires that
size_of_val(self)
andalign_of_val(self)
never deference the self data pointer, and only reads fat pointer metadata like size or vtable. I'm unsure ifTinyBox<T: !Sized>
makes sense, but initial experiments ran into hiccups there.After this, one could create a
SimpleError
trait for error types that avoid allocations, so then some aliastype TinyError = TinyBox<dyn SimpleError>;
provides almost zero cost dynamically typed errors without alloc. In particularTinyError
sounds useful insideRead
andWrite
like trait, which helps #7, but..We'd want a clean story for promoting
TinyError
to larger generic error types with backtrace, etc.The text was updated successfully, but these errors were encountered: