SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Plain enums as index keys with specialized indices

Open Centril opened this issue 9 months ago • 2 comments

Description of Changes

Commits:

  1. Allow plain enums as index keys in Rust and C# bindings. For Rust, FilterableValue is impld when deriving SpacetimeType.
  2. Specialize indices on plain enums by using u8 as the native type. For direct indices on plain enums, the entire index allocated at index creation to the number of tags. This should be quite efficient as the number of tags is expected to be low in the common case.

API and ABI breaking changes

None

Expected complexity level and risk

2?

Testing

SDK tests are added exercising both the host, the modules, and the sdk. New tests are also added for the new fixed capacity direct index type.

Centril avatar Mar 26 '25 16:03 Centril

Requested reviews from:

  • @gefjon for the host internals and sdk tests
  • @coolreader18 for the rust module bindings
  • @kazimuth for the C# bits.

Centril avatar Mar 26 '25 16:03 Centril

I wonder if we should even bother to use unique BTree indices for simple enums, or if we should just impl a unique index on a simple enum column as a direct index. I wonder the same thing about u8 and i8 columns. This is idle speculation, though.

I sorta tried this direction but decided that the user might want to express "this index likely doesn't use all elements" so I skipped that change. It's worth exploring in the future though.

Centril avatar Mar 31 '25 19:03 Centril