perf: increment/decrement len without reading on heap flag - #547
Conversation
|
yeah this is what #451 is trying to do more or less would you want to implement it in full?? I do like your increment thing, maybe you can generalize it to when a type is not a ZST, any increment of length by it would also be helpful (a few notes I took):
|
|
|
Yeah sure, I have 3 or 4 optimization related PRs for smallvec that I'm working on, I can do it after those, But don't block it because of me, if someone is interested let them do it.
I prefer const fn, I saw some weird stuff with generic code optimizations that for these low level stuff I prefer to keep it as simple as possible.
What about putting the flag in MSB instead and always doing +1 and -1? we can use CPU overflow flags and implement it better. I need to review the codebase more carefully, I'm not sure that integer overflows are handled correctly. |
|
I did make a try at storing the flag on the MSB, it's basically the same, except you have to make a mask that only has the MSB on. I do agree that it seems that for repeated length changes it should be faster I'm pretty sure as well that not all integer overflows are handled correctly. literally our current validation is I don't think fuzzing tests that either |
f456662 to
a36e922
Compare
|
Sorry for the force-push, I missed one decrement case. Would you like to merge this one or you prefer the full rewrite? |
|
I prefer it now |
|
the full rewrite is probably going to take some time, so it's not a good idea to rush it to alpha.13 alpha.14 is for September 10 |
3b80c22 to
c832717
Compare
c832717 to
7dd8924
Compare
|
whatever borsh serialization/deserialization does, miri spends a bunch of time on it It needs like 10 minutes |
It's pretty simple and it just bypasses reading the on heap flag by adding 0b10 when type is not ZST.
But I think there is another problem here. set_len is a unsafe operation, in this codebase we can set_len from safe code.
We must follow this by a refactor/fix and making it impossible to set_len from safe API to avoid future mistakes.
Maybe a
UnsafeCell<usize>solution?