ssbc / ssb-db2

A new database for secure-scuttlebutt
47 stars 8 forks source link

feedFormats and encryptionFormats as plugins #347

Closed staltz closed 2 years ago

staltz commented 2 years ago

Context

We are adding buttwoo as a feed format, and it works differently than other formats, so we would introduce a lot of complexity. At the same time, we need to improve the situation of support for box2 before we move on with "ssb-tribes2" on ssb-db2.

Solution

sbot.db.installFeedFormat() and sbot.db.installEncryptionFormat() and encodings.

These are now orthogonal concerns, so any encryption format can work with any feed format, which can support different encodings.

:large_blue_circle: Encoding

An "encoding" is a way of representing a feed message. This PR supports two encodings: 'js' (JavaScript objects) and 'bipf' (BIPF buffers).

:yellow_circle: Feed Format

A feed format defines how to create messages that follow a schema and a spec. Every feed format is a plugin-like object with:

:star: "Native Msg" this concept is new and important. Every feed format has a "native message format", which is a shape for the message that is specific to the feed format. The feed format fully controls its own "nativeMsg" shape, and it can be anything.

:black_circle: Encryption Format

An encryption format specifies how to encrypt and decrypt JavaScript buffers intended for some specific recipients. Every encryption format is a plugin-like object with:

TODO

github-actions[bot] commented 2 years ago

Benchmark results

Part Duration
Create 5000 new messages 455.87ms
Validate 5000 messages 549.00ms
Native to db format 5000 messages 148.89ms
Db to native format 5000 messages 117.29ms
Add 1000 elements 514.47ms
Add 1000 box1 msgs 1193.43ms
Unbox 1000 box1 msgs first run 215.57ms
Unbox 1000 box1 msgs second run 149.08ms
Add 1000 box1 msgs 1143.64ms
Query 1000 msgs first run 47.76ms
Query 1000 msgs second run 31.01ms
Add 1000 box2 msgs 1572.71ms
Unbox 1000 box2 msgs first run 270.02ms
Unbox 1000 box2 msgs second run 189.57ms
Migrate (+db1) 14391.50ms
Migrate (alone) 4862.54ms
Migrate (+db1 +db2) 10710.75ms
Migrate (+db2) 7694.13ms
Migrate continuation (+db2) 1220.48ms
Memory usage without indexes 750.46 MB = 36.20 MB + etc
Initial indexing 836.29ms
Initial indexing maxcpu=86 4573.27ms
Initial indexing compat 957.05ms
Two indexes updating concurrently 1276.12ms
Key one initial 66.04ms
Key two 1.68ms
Key one again 1.35ms
Reboot and key one again 67.01ms
Latest root posts 1016.88ms
Latest posts 9.68ms
Votes one initial 705.68ms
Votes again 0.67ms
HasRoot 544.10ms
HasRoot again 0.57ms
Author one posts 641.06ms
Author two posts 36.11ms
Dedicated author one posts 661.68ms
Dedicated author one posts again 1.16ms
DeleteFeed 3698.71ms
Maximum memory usage 1019.21 MB = 55.20 MB + etc
Indexes folder size 10.01mb