Memory Optimization Strategies for the Tencent Docs Desktop Client
This technical report details the background, proposed solutions, implementation steps, and measurable results of a series of memory‑saving optimizations applied to the Tencent Docs desktop application built with Electron, including container merging, tombstone mechanisms, Windows EmptyWorkingSet API, and Chromium page‑freezing techniques.
Background : The Tencent Docs desktop client, built on Electron, creates a new rendering process for each opened document, leading to high memory consumption of several hundred megabytes per document and causing performance concerns compared to native editors.
Optimization Plan : Initial ideas such as code slimming, resource reuse, and on‑demand loading were deemed too slow. Two fast‑track solutions were explored: (1) Container merging to share a single process for documents of the same category, and (2) a tombstone‑style mechanism that clears background tabs after 30 minutes and when memory usage exceeds a quarter of system memory.
Implementation : The tombstone strategy monitors tab inactivity, triggers EmptyWorkingSet on Windows to release unused pages, and uses Chromium's internal SetPageFrozen method (exposed by modifying Electron) to freeze invisible pages. A custom Node addon was prototyped but not shipped due to security concerns. The combined approach freezes a tab after 3 seconds, performs memory cleaning after 5 seconds, and repeats checks every minute, cleaning again if a process exceeds 50 MB.
Optimization Effects : Benchmarking with six simultaneously opened documents showed memory usage dropping from ~2.5 GB to ~900 MB, a reduction of about 60 %. The strategy reclaimed memory without noticeable impact on user experience.
Summary : By introducing a tombstone mechanism, leveraging Windows EmptyWorkingSet , and integrating Chromium page‑freezing, the desktop client achieved significant memory savings and improved performance.
Future Plans : Further reductions will target decreasing the number of rendering processes, moving more logic to the main process, continued code slimming, on‑demand loading, data‑structure optimization, memory‑leak detection, and exploring containerization for additional gains.
Tencent Docs Tech Team
Based on years of technical expertise from the Tencent Docs team, Tencent Docs Tech shares the front‑store/back‑factory architecture model, the Kaicong atomic collaborative editing engine, large‑scale service practice insights, continuous infrastructure development, AI assistant innovation, and expertise in specialized format editing and massive social collaboration, driving a new revolution in the document space.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.