I made an Electron app which doesn’t use gigabytes of RAM! Electron + SvelteKit + GQL

Building a Lightweight Electron Application with SvelteKit and GraphQL

In the quest to develop efficient desktop applications, I recently crafted an Electron-based app that defies the common norm of excessive resource consumptionโ€”particularly RAM usage. This project demonstrates that with mindful optimization, Electron apps can be both powerful and lightweight.

A prevalent challenge with Electron and Chromium-embedded applications lies in their tendency to consume significant system resources, often resulting in sluggish performance. This happens mainly due to frequent repaints across the interface. To counter this, I employed strategies such as minimizing repaints, exclusively utilizing CSS transforms and opacity changes for animations, and enabling background throttling. These adjustments drastically free up system resources, allowing for more intricate features like 3D animations and visually appealing CSS effectsโ€”such as image and video glow effectsโ€”which are surprisingly inexpensive in terms of performance cost.

For the frontend framework, I chose SvelteKit for its efficiency and simplicity, especially compared to heavier frameworks like React. Iโ€™ve seen Electron apps like Discord consume over 800MB of RAM just for JavaScript heap management, which I aimed to avoid.

The application stack is built with TypeScript, enhanced by an exceedingly strict ESLint configuration to ensure clean code. It integrates GraphQL through Urql and gql.tada, leveraging offline caching and entity normalization to provide seamless offline functionality. For the user interface, I utilize Shadcnโ€™s Svelte components, offering modern and customizable UI elements.

A critical aspect of maintaining performance is offloading intensive tasks to Electronโ€™s utilityProcessโ€”essentially a dedicated Node.js workerโ€”coupled with sophisticated inter-process communication (IPC) mechanisms to coordinate processes efficiently.

Beyond the core functionalities, the app boasts advanced features like a custom subtitle library, OpenGL shader-based video enhancement for artifact removal, and a suite of other innovative enhancements. These collective optimizations showcase how a thoughtful approach to development can produce a resource-efficient, feature-rich desktop application.

If you’re interested in building high-performance Electron apps without sacrificing functionality, I encourage exploring similar optimization techniques. They prove that with the right tools and strategies, lightweight yet powerful applications are entirely achievable.


Leave a Reply

Your email address will not be published. Required fields are marked *