Show HN: OmniDiff – Opensource, super fast, content aware Git difftool, in Rust (github.com)
OmniDiff can diff: code (25 languages), config, images, PDFs, archives, cursors, fonts...
It's fast. It can diff C++ files of tens of thousands of lines in under 100ms, on a 2023 ThinkPad T14s.
It's open source. AGPLv3.
It's based on real diffs. I looked at the 7400 repositories that are listed in Gentoo packages, sampled 2000 diffs and solved them manually to get a good understanding of what is needed, before putting together the diff pipelines for each content type. Incidentally, this also forms the basis of the CI pipeline, so the robustness of the codebase is quite high.
I'm still developing it. It's v0.3.0 at this time. But I have been using it daily as my git difftool for months now, and it works well.
AI Disclosure: Yes, I do use AI. No, I do not vibecode.
87 comments
[ 3.3 ms ] story [ 37.1 ms ] threadIn the meantime, I added support for all other non-code file formats. Hence the name change.
It’s quite a big chunk of functionality.
IMO, you should seek to make this a standard that wins, and hopefully other opportunities that come will be where you make commercial hay. My unsolicited 2c.
I actually don’t care about the commercial license. It’s more of an experiment for my own amusement than an actual attempt at building a commercial project.
If it inspires someone to build another one and we still end up with a better differ, I’m ok with that world. As long as the open source community has a better differ.
Note that there already are at least 3 that I am aware of. But they do perform worse on speed and accuracy.
Diffsitter and Difftastic have been around for a while, both MIT, so I doubt it.
Nobody wants to use AGPL-v3?
https://github.com/ivankovic/omnidiff/blob/main/LICENSE
> steal
Pick one.
Difftastic only diffs code, which is only 2/3 of all diffs.
When only measured on stuff difftastic supports:
Difftastic is perfect on 64% of diffs and near-perfect on 17% more.
Omnidiff is perfect on 90% of diffs and near-perfect on 5% more.
Speed is
p50 - 35ms difftastic vs 4ms OmniDiff p99 - 637ms vs 420ms
Difftastic wins on license. MIT vs AGPL.
But it was worth pointing out the difference in license, it is one of the ways in which the projects differ.
Discrete users would arguably win more with integrity of AGPL, but developers have reasons to prefer MIT.
Hi! as a developer, I personally prefer it when the libraries/tools used in my projects are GPL or another Copyleft license. The drove of MIT projects from the past decade has been depressing.
One feature I miss from difftastic is showing diffs side-by-side on wide terminals, and unified when narrow.
There's a screenshot and video of it here that I wrote a while back: https://nickjanetakis.com/blog/awesome-git-diffs-with-delta-...
In OmniDiff's readme and web version I didn't see a way to do that.
Also Delta has a package for Arch in its official repos. For folks who just want a "it works" experience, that's a pretty big win. With Delta the same package can be installed in the same way on Debian, Arch and macOS with Brew using standard package managers. With OmniDiff, there's 3 different ways to install it (manual deb package on Debian, manual package compile on Arch and brew install on a Mac).
As for packaging. Unfortunately AUR is closed at the moment due to spam. I can add brew commands for Linux, happily.
In terms of “better”. It’s actually somewhat complex, but a simple way to think about it is that if you move a function up or down in the same class, text-based diffs paint that as “Deleted here, Inserted there” where ideally you would want it to say “Moved”.
Since most people do click-and-run most of the time (based on decades long research, n=1), I'll just add paste the link for more examples: https://ivankovic.github.io/omnidiff/showcase/content.html
Any interest in getting the setup upstreamed[1] so that users only need to `git config --global diff.tool omnidiff` to enable it by default? Disclosure: I created `git difftool` a long time ago, and am always happy when builtin support for useful tools are added to it. Feel free to reach out if you'd like help making that happen.
[1] https://github.com/git/git/tree/master/mergetools
It’s a long term goal to solve, but it’s the hardest one.
I’ll definitely reach out to you to upstream. Thank you for the kind offer!
In practice, tree hashing is doing a huge amount of work because most diffs are tiny. Half of all diffs are less than 10 lines, so a hash can extremely quickly match large subtrees.
In a profoundly degenerate case of a C++ header file with only a 20MB array of bytes, it detects a degenerate tree and uses Myers O(N) sequence diffing algorithm instead of treating it as a tree.
I actually don’t know how to do that and stay under a bounded edit distance.
Alternatively, you can crash it if you just encode the entire “Star Trek - In the pale moonlight” episode as a sequence of bytes in a const int array in C++.
I’m sure there’s an interesting result there, but I am not the person to find it :D
Good episode btw
I actually do TWO solutions for each test case: a minimal diff and a maximal diff. Pressing 'm' in the TUI pops up a settings page where you can choose how the diff works.
I am actively researching how many ways there are to "paint" the same diff and user preferences and non-uniqueness of diffs is something I am super interested in.
If you would like to, it would be super useful for me to know what diff you don't like and why. It would help make the diff better for users with different visual preferences.
I feel like the moved code cases would look great in https://github.com/andunieee/twain, I was looking into how I could slurp your code and make it work there (although for some reason I have the impression that I had already seen this repository in the past, I can't remember where).
If I understand your goal correctly, you are looking to especially focus on the visual part of the diff and provide a nice UI for it, and you would like to use OmniDiff as a library?
If so, then let's talk. I have been delaying the design of the API because nobody has a use for it yet, so it is mostly driven by the needs of the CLI/TUI at the moment.
Ping me on my email if you want.
I feel safer, as a user, enjoying the freedoms that the AGPL provides me. (No evil middleman will be able to give me non-free versions of this program.)
You can do this with delta: `git diff | delta --side-by-side`
(If commit A adds a line to the end of a bullet list in markdown and commit B does the same, they will conflict even though resolution is trivial for a human)
I’m not sure if I’m understanding this correctly : so for the remaining 0.05% of code changes, this tool would just… miss it? That seems horrible for a diff tool :O
But so will every other tool, because it is things like a C++ header file with 128MB of PNG data hardcoded as an array.
Editors don’t even open those files.
But then I would rephrase that because it's confusing, and not doing justice to your tool.
Thanks!
The problem is the degenerative syntax tree that TreeSitter produces in case of, for example a multi-million array of bytes. This causes a stack overflow in the TreeSitter C code which takes down the Rust process with it.
The correct solution would be to prevent TS from crashing, or isolate the C<->Rust boundary better.
Or just, not support that for v0.3. Because if you are diffing the collected works of Shakespeare as a binary blob in a C++ header, maybe diffing isn't your biggest problem.
vi opens multi-GB files just fine.
And for multi-TB files, "less -n" works.
You need to broaden your horizons about editors. Not all of then are javascript-based slopfests
Additionally, here's an appropriate XKCD: https://xkcd.com/378/
[1] https://difftastic.wilfred.me.uk/
Difftastic only diffs code, which is only 2/3 of all diffs.
When only measured on stuff difftastic supports:
Difftastic is perfect on 64% of diffs and near-perfect on 17% more.
Omnidiff is perfect on 90% of diffs and near-perfect on 5% more.
Speed is
p50 - 35ms difftastic vs 4ms OmniDiff p99 - 637ms vs 420ms
Difftastic is MIT vs AGPL.
Care to elaborate? What does Omnidiff offer for non-code files?
Note that you do need a terminal with image support, like kitty, alacritty.
If you do not have image support, it does its best with image2ascii, but it is obviously severely limited.
> Omnidiff is perfect on 90% of diffs and near-perfect on 5% more.
I did not find examples in the repo or any way to test what "perfect" or "near perfect" in those cases mean. On the playground you compare against unix diff only. Based on my quick comparisons with difft, I do not see much difference. Could you add a link to comparisons or show how it differs and what are those numbers based on??? I'm not dismissive, just looking for a proof or showcase.
Fair warning: the true comparison is fairly complex and doesn’t really lend itself to “quick comparison”.
Press ? for the help menu.