Speed up rkyv serialization #123
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This tries to make use of the rkyv
CopyOptimizeattribute that can guarantee memcpy-able structs are indeed just that, rather then iterating over each element in the vector.This ran into one oddity however, the archived layout of
QbvhNodeis smaller then the regular layout (128 vs 124 bytes), this is becauseQbvhNodecontains quite a few padding bytes.QbvhNodeFlagsisu8NodeIndexhas au8memberBoth of those cause a (normally) 121-bytes struct to get blown up to 128 bytes.
In this PR I've hackfixed/worked around this issue by making QbvhNodeFlags u64 which obviously isn't what anybody would want, however since I'm not familiar with this project I'd like to open the discussion about what to do with this.
It seems likely that
QbvhNodeneeds to be somehow cache-line aligned (which it is at the moment), but it might be nice to mark the padding bytes inNodeIndexandQbvhNodeexplicitly so it's clear where in the node one can stuff some additional info.Removing the
CopyOptimizeis not the end of the world; but in this case having it speeds up rkyv serialization by about 2x.