Skip to content

hemzaz/wacompact

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wacompact

Force-compact WhatsApp Desktop's LevelDB IndexedDB to purge ghost records that accumulate over time and cause CPU/memory spikes.

The Problem

WhatsApp Desktop stores all message state in a LevelDB database. LevelDB is append-only — when a record is updated (e.g. message ack goes 0→2→4), old versions aren't deleted immediately. They pile up as superseded records across hundreds of SSTable files until a compaction merges them away. WhatsApp never triggers a full compaction on its own.

Over time this causes:

  • CPU spikes every few days as WhatsApp re-scans bloated SSTables
  • High memory pressure from a swollen database (900+ SSTables, 1.5+ GB)
  • Stuck outgoing messages in groups — ghost ack=0 records that retry logic re-reads

The Fix

wacompact calls leveldb_compact_range across the entire keyspace, rewriting all SSTables and purging every superseded record. Typical result: 15–30% fewer files, immediate reduction in CPU and memory usage.

Usage

wacompact [OPTIONS]

Options:
  --db PATH    Path to the LevelDB directory
               Default: ~/Library/Application Support/WhatsApp/
                        IndexedDB/file__0.indexeddb.leveldb
  --dry-run    Show stats only, do not compact
  --verbose    Print record scan progress
  --no-color   Disable ANSI colors
  --help       Show this help

Notes:
  • WhatsApp must be CLOSED before running.
  • Safe to run repeatedly; compaction is idempotent.

Build & Install

Requires LevelDB. On macOS with Homebrew:

brew install leveldb
make
make install   # installs to ~/.local/bin/wacompact

The project also vendors the LevelDB headers and libs locally under leveldb/ and lib/ so it builds self-contained without Homebrew on the include path.

Example Output

wacompact  WhatsApp LevelDB Compactor
──────────────────────────────────────────

  DB       ~/Library/Application Support/WhatsApp/IndexedDB/file__0.indexeddb.leveldb
  Before   930 SSTables  1.62 GB

  ✓ DB opened
  → Compacting  ✓ done in 36.4 s

──────────────────────────────────────────
  After    780 SSTables  1.56 GB
  Freed    150 files  62.0 MB

  ✓ Compaction complete. Safe to relaunch WhatsApp.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors