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

Optimizing Electron Applications for Performance and Efficiency: A Modern Approach

In the ever-evolving landscape of desktop application development, Electron remains a popular choice for creating cross-platform apps. However, one common challenge developers face is optimizing these apps to run smoothly without consuming excessive system resources. Recently, I developed an Electron-based application that stands out by maintaining a minimal RAM footprintโ€”without sacrificing functionality or visual appeal.

Reevaluating Electron App Performance

Many Electron and Chromium-powered applications tend to suffer from sluggishness due to frequent and heavy repaints across the interface. These repaints, often triggered by complex CSS, animations, and dynamic content, can significantly degrade performance. The key to optimization lies in reducing unnecessary repaints and leveraging hardware-accelerated CSS properties.

Strategies for a More Responsive Electron App

  • Limit repaints by using CSS transform and opacity properties exclusively for animations.
  • Enable background throttling to prevent background tabs or windows from consuming resources unnecessarily.
  • Incorporate sophisticated visual effects, such as 3D animations, CSS glow effects on images and videos, which are surprisingly inexpensive in terms of performance.

Framework Selection and Stack Choices

For the frontend framework, I chose SvelteKit due to its lightweight nature and efficient rendering capabilities. Unlike Electron apps that rely on React, which can sometimes consume upwards of 800MB of RAM solely for the JavaScript heap (as seen in some popular apps), SvelteKit offers a more resource-conscious alternative.

The core stack includes:

  • TypeScript with a rigorously enforced ESLint configuration for code quality.
  • GraphQL, utilizing urql and gql.tada for offline caching, entity normalization, and seamless functionality even without an internet connection.
  • UI Components sourced from shadcn/svelte to ensure a clean, modern interface.

Handling Heavy Lifting

Most intensive operations are managed within Electron’s utility processโ€”a specialized Node.js worker environment. Communication between processes employs advanced IPC mechanisms, ensuring smooth and efficient data exchange.

Advanced Features and Enhancements

The application boasts several innovative features:

  • A custom subtitle management library for enhanced video accessibility.
  • OpenGL shader-based video compression artifact removal, resulting in cleaner playback quality.
  • A feature-rich video player with a suite of advanced functionalities.

Conclusion

Achieving a performant Electron app doesn’t require complex trade-offs or sacrificing visual polish. By focusing on efficient rendering techniques, choosing the right frameworks, and offloading heavy operations appropriately, it’s


Leave a Reply

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