Skip to content

Conversation

paultranvan
Copy link
Contributor

@paultranvan paultranvan commented Jul 1, 2025

When receiving a batch of realtime events, we used to treat them
sequentially and do the following:

  • Query the parent folder if it's a file to compute the path
  • Dispatch the mutation

This was highly inefficient, because the dispatch is a costful
operation, especially if the store is filled with documents and queries.
Indeed, each dispatch will trigger the full reevaluation of the existing
queries against the documents in the store.

So, to improve this behaviour we now introduce a debounce mechanism for
relatime events: we wait a fixed amount of time before processing the
events all at once.
To do this, each new realtime event is temporarily stored in a buffer,
and removed once treated.

This impact all treatments involving multiple realtime events, such as
trash, restore, or deletion from trash.

Note the debounce does not negatively affect single realtime events, as
we force the first event to be treated immediatly (and debounce only the
next ones if they occur less than 500ms after).

To show how impactful this is, we measured how long takes a folder to be
put in the trash. The folder contains 1K files.

  • Before : ~61000 ms 🐢
  • After : ~700 ms 🐇

=> This is a x87 improvements 🚀

Copy link

bundlemon bot commented Jul 1, 2025

BundleMon

Files updated (6)
Status Path Size Limits
services/qualificationMigration.js
282.97KB (+378B +0.13%) -
services/dacc.js
265.16KB (+329B +0.12%) -
public/static/js/cozy.(hash).js
712.36KB (+326B +0.04%) -
public/static/js/public.(hash).js
87.45KB (+274B +0.31%) -
static/js/cozy.(hash).js
846.3KB (+265B +0.03%) -
static/js/main.(hash).js
118.48KB (+258B +0.21%) -
Unchanged files (15)
Status Path Size Limits
static/js/(chunkId).(hash).js
967.38KB -
public/static/js/(chunkId).(hash).js
872.3KB -
(hash).js
337.62KB -
public/(hash).js
337.62KB -
public/static/js/lib-react.(hash).js
39.37KB -
static/js/lib-react.(hash).js
39.37KB -
public/static/css/cozy.(hash).css
33.69KB -
static/css/cozy.(hash).css
33.69KB -
public/static/js/lib-router.(hash).js
22.05KB -
static/js/lib-router.(hash).js
22.05KB -
static/css/main.(hash).css
16.62KB -
public/static/css/public.(hash).css
6.3KB -
manifest.webapp
1.89KB -
index.html
689B -
assets/manifest.json
185B -

Total files change +1.79KB +0.04%

Groups updated (1)
Status Path Size Limits
**/*.js
6.45MB (+2.35KB +0.04%) -
Unchanged groups (2)
Status Path Size Limits
**/*.{png,svg,ico}
2.15MB -
**/*.css
129.79KB -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@paultranvan paultranvan force-pushed the slow-trash branch 2 times, most recently from ede8592 to 9b992f0 Compare July 2, 2025 14:49
The provided files is an array, but an empty array is truthy, so it was
rendering the `DestroyConfirm` for nothing.
When receiving a batch of realtime events, we used to treat them
sequentially and do the following:
- Query the parent folder if it's a file to compute the path
- Dispatch the mutation

This was highly inefficient, because the dispatch is a costful
operation, especially if the store is filled with documents and queries.
Indeed, each dispatch will trigger the full reevaluation of the existing
queries against the documents in the store.

So, to improve this behaviour we now introduce a debounce mechanism for
relatime events: we wait a fixed amount of time before processing the
events all at once.
To do this, each new realtime event is temporarily stored in a buffer,
and removed once treated.

This impact all treatments involving multiple realtime events, such as
trash, restore, or deletion from trash.

Note the debounce does not negatively affect single realtime events, as
we force the first event to be treated immediatly (and debounce only the
next ones if they occur less than 500ms after).

To show how impactful this is, we measured how long takes a folder to be
put in the trash. The folder contains 1K files.

- Before : ~61000 ms
- After : ~700 ms
@paultranvan paultranvan merged commit b5ca415 into master Jul 17, 2025
4 checks passed
@paultranvan paultranvan deleted the slow-trash branch July 17, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants