SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

WebSocket: Store one protocol tag per list of rows and avoid an allocation per row

Open Centril opened this issue 1 year ago • 0 comments

Basically, implement what is suggested here: https://github.com/clockworklabs/SpacetimeDB/pull/1077#discussion_r1645916998

The basic idea (names and such are not important, only the structure) is:

pub struct TableUpdate {
    ...
    pub inserts: EncodedValueVec,
    pub deletes: EncodedValueVec,
}

// The choice is done at the level of list of rows, not on the level of rows.
enum EncodedValueVec {
    Binary(BinaryVec),
    Text(Vec<ByteString>),
}

// Identical to `packed_str::PackedStr`, but the interface will deal with bytes, not strings.
// Thanks to `indices` being present,
// we preserve the ability to do parallel decode at the cost of making `EncodedValueVec` larger.
struct PackedBytes {
    indices: Vec<usize>,
    rows_data: Vec<u8>,
}

This EncodedValueVec would be used every time we have Vec<EncodedValue> making the number of tags O(1) rather than O(rows).

Centril avatar Jun 20 '24 08:06 Centril