Skip to content

perf: snapshots: use TextEncoder instead of new Blob to fix heavy GC lag - #2441

Merged
mbnuqw merged 3 commits into
mbnuqw:v5from
llc0930:textencoder
Aug 12, 2026
Merged

perf: snapshots: use TextEncoder instead of new Blob to fix heavy GC lag#2441
mbnuqw merged 3 commits into
mbnuqw:v5from
llc0930:textencoder

Conversation

@llc0930

@llc0930 llc0930 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Tested for over a month in an environment with 9,000+ tabs and the Firefox profile on a traditional HDD, with a noticeable reduction in perceived lag when deleting snapshots.

Lower GC by allocating and keeping ~10mb buffer for size
measurements.
@mbnuqw

mbnuqw commented Aug 12, 2026

Copy link
Copy Markdown
Owner

I profiled both methods (Blob and TextEncoder) with a non-ASCII character set (Zh): Both methods produced approx the same memory footprints. Both methods triggered string re-encoding (x2 CPU usage compared to ASCII-only chars) + memcpy. And they showed more or less the same GC behavior. The Blob method has a bit lower memory threshold that triggers GC, which probably causes this effect. But if the data size continue to grow, you'll start experiencing heavy GC lag with TextEncoder too.

To fix this we can pre-allocate and keep some memory for measuring (e.g. 10mb). But it brings two trade-offs:

  • size measurement will be strictly limited to this 10mb, which is ok, there is a hard limit of 10mb on all snapshots anyway (or we could dynamically re-create this buffer, but this will trigger GC...).
  • this 10mb of RAM will always be consumed by Sidebery. I think we can afford such luxury even these days.

btw, this size measurement will be removed when I migrate snapshots storage to OPFS.

@mbnuqw
mbnuqw merged commit 9d05587 into mbnuqw:v5 Aug 12, 2026
2 of 3 checks passed
@llc0930
llc0930 deleted the textencoder branch August 12, 2026 14:34
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.

2 participants