Manually adding padding to `FastStr` gains 9x boost on performance, but why?
Hi, I'm the author of \FastStr\\ crate, and recently I found a wired problem that the clone cost of \FastStr\\ is really high. For example, an empty \FastStr\\ clone costs about 40ns on amd64 compared to about 4ns of a normal String.
After some time of investigation, I found that this is because the \Repr::Inline\\ part has really great affect on the performance. And after I added a padding to it(change the type of \len\\ from \u8\\ to \usize\\), the performance boosts about 9x. But the root cause is still not clear.
Related PR: https://github.com/volo-rs/faststr/pull/6
Furthermore, I've tried the following methods, but none helps:
- change \
INLINE\\_CAP\\to 24 - change \
INLINE\\_CAP\\to 22 and added a padding to the Inline variant: \Inline {\\_pad: u64,len: u8,buf: \\[u8; INLINE\\_CAP\\],},\\ - change \
INLINE\\_CAP\\to 22 and add a new struct \Inline\\without the \\\_pad\\field
To change the \INLINE\\_CAP\\ to 22 is only for not increasing the size of \FastStr\\ itself when add an extra padding, so the performance is nothing to do with it.
Edit: rust issue: https://github.com/rust-lang/rust/issues/119247