-
-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Checklist
- Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
- Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/
Describe the bug
The size of the object store grows every time the page is refreshed. This occurs because the doc is encoded as an update and appended to the object store every time IndexeddbPersistence
is instantiated.
The db is compacted after reaching the PREFERRED_TRIM_SIZE
whenever an update is stored. However, this assumes 1) a small number of Docs, and 2) Docs will be modified. While reasonable on the surface, neither of these assumptions hold in all cases. I currently instantiate thousands of Docs for an offline-first graph database built on YJS. Many hundreds are instantiated and destroyed dynamically as the user navigates the graph, and some may never be modified.
To Reproduce
Minimal example:
https://codesandbox.io/p/sandbox/pedantic-euler-jje92f?file=%2Fsrc%2FApp.tsx%3A1%2C1-2%2C1
Notice that no modifications are made to the Doc, yet it grows in size.
Expected behavior
The persisted Doc should not grow indefinitely when no changes are made.
Environment Information
- Browser: Chrome
- Yjs: v13.6.2
- y-indexeddb: v9.0.11
Additional context
I can see that the behavior was introduced in this commit.
One possible solution is adding the condition if (updates.length === 0)
to beforeApplyUpdatesCallback
, as it seems to only be needed on a new Doc. That stops the infinite growth, and the tests pass, however I don't know the full implications of this change. If beforeApplyUpdatesCallback
needs to be invoked in other cases that are not covered by the tests that would be important to know.
Is there a condition that detects when beforeApplyUpdatesCallback
does not need to be called? I have tried skipping it when the Doc is empty, but that does not work.