Spekter
Spekter is a GUI application for diffing files and recursive directory trees. Its aim is to be instant. Tabs open immediately, file content appears at once, and the diff colouring fills in with no delay.
Invention through boredom
A few years ago, I worked on a project where we needed to convert old XML files into a new format. The files were not very big, but they were numerous and spread across different folders. While we were working on code to get the conversion for all the different types of XML right, and constantly stumbled across new corner cases, a cron process in the old system updated them every night, and our conversion code needed to stay idempotent and error-free every day. We did a lot of testing on our systems, but sometimes needed manual inspection of the XML files, especially after larger refactorings of the conversion code.
Voilà, there was the need. We had to compare thousands of files in different subfolders,
and most of them were identical from one day to the next. So did we turn to
diff (diff -r or
diff -rq)? Nope, not when doing human inspection. We turned to
Meld.
Visual diff tools like Meld (or KDiff3 or Diffuse or ...) are wonderful, but on large directory trees they can spend several seconds churning before anything appears. So there we were, on a daily basis, looking at a comparison that seemed in no hurry to show up on screen. Waiting for the diff was so boring we just had to do something about it ...
Spekter is built the other way around. It shows what it already has first, and keeps computing in the background. Opening a comparison of a 50 000-file tree is not really any different from showing a 10-file tree. The window appears, the tree fills in, and you can start clicking long before the last file has been compared.
Two small choices make this work:
- file content is read and rendered before any colour-coding is computed, and
- the diff algorithms run off of the UI thread
First of all, we show what we have. A blank screen while waiting is really, really boring. Second, we do the diffing on a separate thread so that the UI isn’t clogged. The diffing actually is really fast (see next paragraph), but it’s still a good principle to do nothing but UI work on the UI thread. In Spekter, it’s one of the most important rules we have. It keeps the UI responsive.
The choice of diff algorithms also matters. Spekter uses imara-diff, and to give results instantly, we set off with two checks at the same time: both the histogram algorithm and the Myers algorithm. (Files <1MB only with histogram, but bigger files get both.) On some files, histogram will finish first and Myers will be slow, on others it’s the other way around. Whichever finishes first is used, the other one is stopped and discarded. This allows Spekter to present diff results extremely fast across a wide range of workloads. Generally, imara-diff is also one of the fastest diff libraries around. On complex diffs, the more commonly used similar crate falls so far behind that the comparison charts on imara-diff’s crates.io page have to use a logarithmic scale! The benchmarks there are run against real repositories (Linux kernel, Rust compiler, VSCode, the Helix editor), so the numbers reflect actual diffing work, not just dummy inputs.
Beyond «Yet Another Lookalike»
Spekter has the same basics as all other graphical diff tools. We have side-by-side and unified views, synchronised scrolling, character-level inline highlights, tabs, and Bezier gutter connectors between hunks. A few other features came to us out of practical use (admittedly mostly about JSON):
- Structural slider adjustment. When an inserted block in a JSON array would otherwise land mid-object, Spekter nudges the hunk boundary to the nearest structural seam so the inserted object is marked as one unit rather than split across two
- JSON and CSV order detection. When two files hold the same items in a different order (array elements and object keys in JSON, rows in CSV), Spekter says so, instead of showing a wall of red and green
- CRLF normalisation. Line-ending mismatches don’t fill the diff with false positives (unless you want them to, but then they’re not false positives, are they?)
- Binary file handling. Non-text files simply report identical or differ with file sizes, rather than trying to render garbled bytes
- Smart ignore. Skips
.git,.idea, swap files, backups and other usual noise by default
Terminal mode for headless environments
Spekter ships a second binary, spekter-nw, that does the same diff work
without opening a window. Same comparison logic, same colour-coded output, but
rendered to your terminal instead. Useful over SSH, in a remote CI shell, or just
when you’d like to pipe a diff into less.
spekter-nw /path/to/old /path/to/new
Both binaries share the diff core, so a side-by-side comparison in the GUI and a
quick spekter-nw on the command line will agree about what differs.
Installation
On Linux, Spekter is in both big app stores, Flathub and Snap Store.
flatpak install flathub org.babelserver.spekter # or sudo snap install spekter
On other platforms, or if you prefer to build things yourself, all you need is Rust itself:
git clone https://gitlab.com/hallyhaa/spekter cd spekter cargo build --release
The binaries end up in target/release.
Spekter used to be on crates.io
too, but those crates are abandoned for now, and what you find there is old.
Please don’t cargo install it. We have git dependencies in
the code base, and Crates.io only accepts dependencies from its own registry,
so publishing will have to wait until the forks we have on GitLab are no longer
needed.
The shortcuts to both stores, and to the source code, are in the badges at the top of this page.