Closed forrestli74 closed 2 years ago
I want to start by saying this: For the tinyvec
crate, the forbid(unsafe)
rule is absolute. I don't think all code needs to stick to such a rule (I started bytemuck
after all), but this crate has self-imposed that forbid(unsafe)
is part of our advertised contract with our users.
As to the main request: Yeah I could update the readme with a little compare and contrast segment.
I updated the readme a bit, I'm not sure if it fully answers all of your questions though. https://github.com/Lokathor/tinyvec/commit/65dcba2655d780387779f4c7c273b2746c42ba11
Thanks! I think Default
requirement is not the only weakness of forbid(unsafe)
. It also forbids smaller mem size through union.
But the commit does help clarify things. Feel free to close the issue if you don't think it's worth mentioning.
I'll close this.
(Generally one doesn't end up having a container of containers, so saving 8 bytes off the size of the vec doesn't seem like as big a deal to me.)
tl;dr: It's really useful for people to decide which crate to choose. Could you add something to README?
Based on my research, I summarize it as:
They both solve the same issue with similar approach. smallvec is older hence more stable and has more user. But it's owned be servo team, and is potentially dead. tinyvec is unsafe-free (which I think should not be a hard rule, since bug-free != unsafe-free), and is still being actively improved.
In terms of time/op performance, tinyvec is still improving on this, the latest status is that it's faster for common ops and slower in other ops.
Other advantage for tinyvec: more variants (such as ArrayVec)
Other advantage for smallvec: smallvec has more feature flags which allow granular performance tweak. Such as: union feature allows smaller mem size (32 byte to 24 byte).
I can open a separate issue if you want, but I think smallvec union feature is really nice, and would be nice for tinyvec to have it. But it's impossible without unsafe code.
Could you add something like this to the doc? I also want to know, is tinyvec trying to be smallvec but better? or tinyvec tries to solve for slightly different scenario?
If you want I can reword and submit a PR to add what I wrote to README.