Skip to content

Conversation

@markbt
Copy link

@markbt markbt commented Jan 11, 2023

The Abomonation crate allows transmutation of types into buffers of memory and back again. This is useful for caches, where it makes it possible to serve read-only references of the item directly out of the cache memory.

Abomonation implements support for normal vectors, however it needs each type to implement the Abomonation trait in order for it to work on them. We have structures containing smallvecs that we'd like to serialize with Abomonation, but currently can't as it doesn't implement the trait.

This change adds a new feature (abomonation) to the smallvec crate which provides abomonation support for SmallVec if specified. The implementation is based on the Abomonation Vec implementation, with the unspilled special case accounted for: the data is inline, so doesn't need to be stored separately.

I've put this behind a feature flag as I'm sure most users won't want it. However we might not be the only ones using both SmallVec and Abomonation, so I thought I'd share it to see if there is interest in incorporating it here.

The `abomonation` crate allows transmutation of types into buffers of
memory and back again.  This is useful for caches, where it makes it
possible to serve read-only references of the item directly out of the
cache memory.

The `abomonation` crate implements support for normal vectors.  This
change adds a new feature (`abomonation`) to the smallvec crate which
provides abomonation support for `SmallVec`, too.
@markbt
Copy link
Author

markbt commented Jan 13, 2023

As an alternative, I've also written TimelyDataflow/abomonation#45 which adds the implementation to the abomonation crate via a feature flag there. I think that might be the preferred option, as it isolates the somewhat crazy implementation to that crate, but I'll leave this PR up for now in case there is interest here.

@mbrubeck
Copy link
Collaborator

I'm fine either way, but if you think that putting the code in abomonation makes more sense, I'll wait and see if that PR is accepted first.

@markbt
Copy link
Author

markbt commented Feb 2, 2023

To follow up on this - I ended up trying to remove our usage of abomonation and replace it with bincode instead, as bincode 2.0 can perform roughly as well as abomonation if suitably optimized. However, you'll need to implement the new bincode Encode and Decode traits for that, which I will open a PR for shortly.

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #298) made this pull request unmergeable. Please resolve the merge conflicts.

@mbrubeck mbrubeck deleted the branch servo:master September 20, 2023 17:19
@mbrubeck mbrubeck closed this Sep 20, 2023
@mbrubeck
Copy link
Collaborator

(This was auto-closed because the master branch was deleted. You may re-submit this pull request against the v2 branch.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants