Ensure EventIds and Positions are unique within a LinkedChunk and that Events are synchronized across LinkedChunks - #6872
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6872 +/- ##
==========================================
+ Coverage 90.10% 90.14% +0.04%
==========================================
Files 407 407
Lines 115745 115794 +49
Branches 115745 115794 +49
==========================================
+ Hits 104294 104385 +91
+ Misses 7540 7500 -40
+ Partials 3911 3909 -2 ☔ View full report in Codecov by Harness. |
Merging this PR will degrade performance by 92.99%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | Event cache room updates[memory][room count: 100] |
5.3 s | 1,391 s | -99.62% |
| ❌ | Simulation | Linked chunk writing [memory store][1000] |
7.1 ms | 128.3 ms | -94.5% |
| ❌ | Simulation | Event cache room updates[memory][room count: 10] |
527.6 ms | 8,388.4 ms | -93.71% |
| ❌ | Simulation | Event cache room updates[memory][room count: 1] |
53.1 ms | 163.1 ms | -67.47% |
| ❌ | Simulation | Linked chunk writing [memory store][100] |
711.5 µs | 1,814.7 µs | -60.79% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing mgoldenberg:indexeddb-event-unique-in-linked-chunk (e18f0dd) with main (1d4bc12)
62e14a4 to
437d5dc
Compare
Hywan
left a comment
There was a problem hiding this comment.
I think we are good, except maybe one test that could be improved, thoughts?
| }); | ||
| } | ||
|
|
||
| async fn test_linked_chunk_push_items(&self) { |
There was a problem hiding this comment.
You are missing the case where you are pushing an existing event in a free position.
Normally we have the Deduplicator for that, but we need to ensure the storage will have a uniqueness constraint too.
There was a problem hiding this comment.
I think this is handled by operation (5) in my comment above, no?
|
I'm also sad about the performance regression. I'm afraid it could impact us. Do you feel we can do something about it? |
As far as I can tell, the regression is only in the memory store, correct? I haven't looked into it yet, but I think we could probably add another data structure to help speed up some of the searches. The downside, of course, is that there will be more data redundancy. What do you think? I'm happy to look into it! |
Ah yes, of course, not a problem then, I don't really care about the memory store, it's mostly for testing purposes. |
|
So, it looks like the benchmarks for the event cache have not been run for any of the more recent commits. Things seems to fail in another job and then cancel the remaining benchmarks. Are you able to restart those, @Hywan? |
|
Jobs restarted. |
|
Can you rebase your fixup commits please? They look good to me. |
Hywan
left a comment
There was a problem hiding this comment.
Looks good to me, just need to rebase.
…onsistent The targeted case is when Update::PushItems is being processed by EventCacheStore::handle_linked_chunk_updates. The behavior should ensure that when an event is added, all existing instances of that event across all linked chunks should be updated to reflect the most recently added event contents. Additionally, it should ensure that no two events can occupy the same position in a single linked chunk and that the same event cannot exist in a linked chunk more than once. Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
…re unique within a linked chunk Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
…tent events Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
…linked chunks Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
…tes all instances The targeted case is when Update::ReplaceItem is being processed by EventCacheStore::handle_linked_chunk_updates. The behavior should ensure that when an event is replaced, all existing instances of that event across all linked chunks should be updated to reflect the most recently added event contents. Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
…er linked chunks Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
…es all instances in the store Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
Signed-off-by: Michael Goldenberg <m@mgoldenberg.net>
e18f0dd to
c090e8f
Compare
This pull request enforces three properties on implementations of
EventCacheStorethrough integration tests.Eventshould not exist within aLinkedChunkmore than once - i.e., it should occupy only a singlePosition.Positionwithin aLinkedChunkshould only be occupied by a singleEvent.Eventin oneLinkedChunk, these changes should be reflected in allLinkedChunks which contain an instance of thatEvent.Enforcing these properties required adding and updating integration tests, as well as some modifications to each of the
EventCacheStoreimplementations - i.e., in-memory, SQLite, and IndexedDB.Changes
Integration Tests
A new integration test was added to
EventCacheStoreIntegrationTests- i.e.,test_linked_chunk_push_items. This test enforces that implementations conform to properties (1), (2), and (3) above when processing anUpdate::PushItems.Furthermore,
test_linked_chunk_replace_itemhas been updated to ensure that implementations adhere to property (3) above when processing anUpdate::ReplaceItem.In-Memory
In the in-memory implementation of
EventCacheStore, the following steps were taken to ensure compliance with the properties above.Update::PushItemsandUpdate::ReplaceItemto ensure compliance with (1) and (2) above.Positions are removed when processingUpdate::RemoveItem,Update::DetachLastItems, andUpdate::Clearto ensure compliance with (2) above.Eventcontent is updated acrossLinkedChunks when processingUpdate::PushItemsandUpdate::ReplaceItemto ensure compliance with (3) above.Performance
This results in a significant performance penalty, as ensuring these properties often requires iterating over many items. That being said, I don't think performance is much of a concern for this implementation, as it is used primarily for testing.
SQLite
In the SQLite implementation of the
EventCacheStore, changes were mininmal as it was already compliant with properties (2) and (3) above. All that was required was to establish a uniqueness constraint on theLinkedChunkIdand theEventIdin theevent_chunkstable to ensure compliance with (1) above.These changes were discussed in #6844.
IndexedDB
The IndexedDB implementation was already compliant with properties (1) and (2) above. It did not, however, properly update
Events acrossLinkedChunks when processingUpdate::PushItemsandUpdate::ReplaceItem.In order to do this efficiently, a new (non-unique) index was added to the
EVENTSobject store which tracks theEventIdof anEvent, regardless of theLinkedChunkin which it exists. This allows allEvents in allLinkedChunks with the sameEventIdto be retrieved in a single query.Additionally,
IndexeddbEventCacheStoreTransaction::{add_event, put_event}were updated to ensure that they retrieved allEvents in the store with the providedEventIdand updated with the provided content. This ensured compliance with property (3) above.Performance
While there don't seem to be any benchmarks for the IndexedDB implementation, this will certainly result in a performance penalty. This is because processing
Update::PushItemsandUpdate::ReplaceItemnow updates all instances of anEventacross allLinkedChunks, which is not possible to do without reading them all into memory, modifying them, and then writing them back to the database.Signed-off-by: Michael Goldenberg m@mgoldenberg.net