惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
N
News and Events Feed by Topic
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
Simon Willison's Weblog
Simon Willison's Weblog
W
WeLiveSecurity
H
Hacker News: Front Page
L
LINUX DO - 热门话题
T
Tor Project blog
N
News | PayPal Newsroom
S
Secure Thoughts
小众软件
小众软件
Recent Commits to openclaw:main
Recent Commits to openclaw:main
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
AWS News Blog
AWS News Blog
Security Latest
Security Latest
MyScale Blog
MyScale Blog
Webroot Blog
Webroot Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
腾讯CDC
T
Tailwind CSS Blog
SecWiki News
SecWiki News
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
GbyAI
GbyAI
C
Check Point Blog
博客园_首页
PCI Perspectives
PCI Perspectives
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
aimingoo的专栏
aimingoo的专栏
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家

Hacker News

Introducing Claude Opus 4.7 Qwen Studio The Future of Everything is Lies, I Guess: Where Do We Go From Here? GitHub - SeanFDZ/macmind: Single-layer transformer in HyperTalk for the classic Macintosh Show HN: Agent-cache – Multi-tier LLM/tool/session caching for Valkey and Redis Moving a large-scale metrics pipeline from StatsD to OpenTelemetry / Prometheus GitHub - Nightmare-Eclipse/RedSun: The Red Sun vulnerability repository GitHub - SethPyle376/hiraeth: Local AWS emulator focused on fast integration testing, with SQS support, SQLite-backed state, and a debug-friendly web UI. GitHub - macOS26/Agent: Any AI, replaces Claude Code, Cursor, OpenClaw. Over 18 LLM providers (Claude, OpenAI, Gemini, Ollama, Zai, HF, Qwen) wired into a native Mac app that writes code, builds Xcode projects, bumps versions, manages git, automates Safari, use AppleScript, JS or Accessibility, extend Agent! w/ MCP Servers, run tasks from your iPhone via Messages. YouTube now lets you turn off Shorts I Made a Terminal Pager Burgers | マクドナルド公式 Commands — HackerNews CLI documentation ChatGPT for Excel PiCore - Raspberry Pi Port of Tiny Core Linux Live Nation illegally monopolized ticketing market, jury finds Google Broke Its Promise to Me. Now ICE Has My Data. Founding Engineer at Adaptional | Y Combinator CRISPR takes important step toward silencing Down syndrome’s extra chromosome GitHub - saffron-health/libretto: The AI toolkit for building reliable browser automations US v. Heppner (S.D.N.Y. 2026) no attorney-client privilege for AI chats [pdf] Unexpected €54k billing spike in 13 hours: Firebase browser key without API restrictions used for Gemini requests Retrofitting JIT Compilers into C Interpreters IPv6 – Google The Accursèd Alphabetical Clock Cybersecurity Looks Like Proof of Work Now Fragments: April 14 Cal.com Goes Closed Source: Why AI Security Is Forcing Our Decision | Cal.com - Scheduling Software for Online Bookings Laravel raised money and now injects ads directly into your agent When moving fast, talking is the first thing to break Too much Discussion of the XOR swap trick – Heather Cafe Introduction to Spherical Harmonics for Graphics Programmers The Grand Line Building a Z-Machine in the worst possible language High-Level Rust: Getting 80% of the Benefits with 20% of the Pain GitHub - duguyue100/midnight-captain: Inspired by Midnight Commander, tailored to my taste. How to build a `git diff` driver · Jamie Tanna | Software Engineer Center for Responsible, Decentralized Intelligence at Berkeley The Local Universe’s Expansion Rate Is Clearer Than Ever, but Still Doesn’t Add Up - A new synthesis of astronomical measurements confirms a persistent mismatch that could point to physics beyond current models The air throughout our homes is infused with microplastics. But there are things you can do to breathe less of them The disturbing white paper Red Hat is trying to erase from the internet – OSnews The Future of Everything is Lies, I Guess: Annoyances ‘Abhorrent’: the inside story of the Polymarket gamblers betting millions on war Productive procrastination — Max van IJsselmuiden maps, territory and LMs 447 Terabytes per Square Centimetre at Zero Retention Energy: Non-Volatile Memory at the Atomic Scale on Fluorographane Show HN: Pardonned.com – A searchable database of US Pardons 20 Years on AWS and Never Not My Job The Seasons are Wrong Artemis II crew splashes down near San Diego after historic moon mission We gave an AI a 3 year retail lease in SF and asked it to make a profit | Andon Labs How a dancer with ALS used brainwaves to perform live On filing the corners off my MacBooks Installing every* Firefox extension OpenClaw’s memory is unreliable, and you don’t know when it will break Steve Blank Nowhere Is Safe Chimpanzees in Uganda locked in vicious 'civil war', say researchers watgo - a WebAssembly Toolkit for Go linux/Documentation/process/coding-assistants.rst at master · torvalds/linux GitHub - callumlocke/json-formatter: Makes JSON easy to read. Founding Product Engineer at Bild AI | Y Combinator A compelling title that is cryptic enough to get you to take action on it GitHub - Keychron/Keychron-Keyboards-Hardware-Design: Industrial design files for Keychron keyboards and mice. 100+ models with CAD assets in STEP, DXF, DWG, and PDF. Source-available, with commercial use allowed for original compatible accessories within the license terms. [ANNOUNCE] WireGuardNT v0.11 and WireGuard for Windows v0.6 Released 1D-Chess Helium Is Hard to Replace Cooperative Vectors Introduction | Evolve Keeping a Postgres queue healthy — PlanetScale Our response to the Axios developer tool compromise Do Americans read print books, e-books or audiobooks more? The Zettelkasten Method in Obsidian: A Practical Setup Guide Artemis II Is Competency Porn and We Are Starving For It WeakC4 Flight Viz — Cockpit View A Mexican surveillance giant you’ve never heard of is now watching the U.S. border Surelock: Deadlock-Free Mutexes for Rust RISC-V 101 – what is it and what does it mean for Canonical? | Ubuntu The Problem That Built an Industry How Much Linear Memory Access Is Enough? | Solidean Investigating Split Locks on x86-64 Simplest hash functions Sybilproof reputation mechanisms (2005) [pdf] What is a property? How Complex is my Code? Static code analysis in Kotlin — tools overview Toffoli gates are all you need PGLite evangelism dcmake: a new CMake debugger UI Clojure on Fennel part one: Persistent Data Structures Fragments: April 2 Python Release Python install manager 26.1 The Life and Death of the Book Review - Liberties Introducing Database Traffic Control — PlanetScale Bitcoin miners are losing $19,000 on every BTC produced as difficulty drops 7.8% God sleeps in the minerals Building slogbox Apple Silicon and Virtual Machines: Beating the 2 VM Limit Who was “Not Even Wrong” first? Pokemon Evolution Vs Darwinian Evolution The APL Programming Language Source Code
Lossless GIF recompression via exhaustive search
Arusekk · 2026-06-22 · via Hacker News

A bit of history

GIF is the oldest widespread compressed image format. Today, it is mostly famous for allowing animations in an image file, but I am not so interested in that use.

Actually, it turns out this was the only image format ever supported by NCSA Mosaic. Your website must have a GIF fallback for all critical images if it ever wants to truly support old browsers. I’m not talking old as in old Chromium. I mean actual Mosaic, Netscape, IE, Netsurf, Dillo, Konqueror - like those you can try on oldweb.today. (You are probably not interested in supporting them, but this is a fun exercise.)

I really wanted the 1-Click Linux website to look acceptable even in the oldest browsers, so I decided that I would use <picture> with fallback to GIF. I believe each modern web feature, if used in production, should be reasonably widely compatible on itself already, and then only have one fallback, which should be the one with absolute 1000% compatibility.

Problem

The problem is, GIF compression is not impressive. Let’s face it, in 2026 you should most likely only use SVG and WebP (lossy for photos, lossless for small-pallette drawings/logos). Not PNG, not JPEG, and God forbid AI, DWG or any other proprietary format (looking at you, DICOM). Well, okay, at least on the web (as the name says, WebP).

A partial solution is to use a small image. The truly old devices have truly small screen sizes, like 240x320 Nokia phones. So an icon or logo fallback can safely be 128x128, as 256x256 might not even fit on the screen.

Can we do better? Yes. There is an entire field dedicated to image optimisation, and it starts with stripping metadata. Then we can remove unused colors from the palette, then remove rarely used colors from the palette, and so on.

But none of the steps above mention actual compression itself!

ZopfliPNG

I heard about zopflipng. PNG uses DEFLATE, the compression format known from ZIP and GZIP. This is a variant of LZ77 with Huffman coding. In this format, and quite commonly in other compression formats, there are many different ways to represent the exact same uncompressed data.

DEFLATE is also the name of an algorithm that generates a reasonably compressed input, and it can be tuned to spend more time compressing in hopes to achieve better compression (for the same data, remember?). But there are many syntactically valid DEFLATE streams that are never produced by DEFLATE the algorithm, which is kind of funny, because you can make a ZIP that contains itself, but anyway, some of them are even better than the largest ‘compression level’.

Now, Zopfli is the software that performs an exhaustive search across all possible syntactically valid streams, in order to find what is actually the smallest number of bits to represent the given uncompressed input. Then ZopfliPNG is the variant that does it for PNG and also explores the PNG pixel encodings. We need to be careful here, because finding the actual best compression for an arbitrary format can be equivalent to solving the halting problem. But the compression formats we talk about today have some helpful invariants guaranteeing the search always halts.

ZopfliGIF?

There is no ZopfliGIF, but there is flexiGIF, which does almost exactly that. It is obviously a wonderful tool, and you should go use it on all your GIFs. But the thing is, GIF uses a very different compression scheme - LZW. And I found a baffling remark in its README, saying that it can leave files larger than the original algorithm. This was very suspicious. So I set out on an exploration. ‘It was made by a single human - therefore I can understand it, too.’ - thought I.

LZW

Then I found it a bit difficult to understand, because like all the papers from that time, the original description insists on building the data format around the algorithm. But we, decades later, already know that this is a mistake: for us, interoperability-focused people, the data format is more interesting, of course, than the algorithm. Changing the format requires changing the decoder software. Keep the format, change the encoder software, and enjoy still using the same decoders. Compatibility.

To save you some time, let me describe it to you: compressed stream consists of actions, each either saying ‘yield this byte’, or naming a previous action and saying ’re-do all of this operation again, but then also add the first byte of the action that followed’. (The edge case of choosing the last action works just fine, and is called KwKwK in the paper.) (GIF also has an ’end of data’ action and a ‘zero the state’ action, but this is not relevant.)

Simple, right? Well, it does sound simpler to me at least. Way simpler than starting the understanding by reading 9 lines of compression pseudocode, and 9 lines of corresponding decompression pseudocode.

Then the algorithm can be simply expressed as the greedy approach, looking at all the previous actions, and taking the longest one that matches what follows. This is doubly reasonable, since (a) what is locally best at least has a chance of being globally best, and (b) it always adds a new ‘word’ to the ‘vocabulary’.

To save you some time, here is an example stream for compression:

a b a b a b a a b a a b a a a b

One of the possible ways (the greedy way) to split it is:

a b a-b a-b-a a-b-a-a b-a a a-b
1. Say a. (no way to say ab; replaying this action will say ab)
2. Say b. (no way to say ba; replaying this action will say ba)
3. Replay action 1. (says ab, no way to say aba; replaying this one will say aba)
4. Replay action 3. (says aba, no way to say abaa; replaying this one will say abaa)
5. Replay action 4. (says abaa, no way to say abaab; replaying this one will say abaab)
6. Replay action 2. (says ba, no way to say baa; replaying this one will say baa)
7. Say a. (no way to say aa; replaying this one will say aa)
8. Replay action 1. (says ab. no way to say abEOF; the last one is never replayed,
                     but it would go aba or abb depending on what would be
                     the first letter of 9)

But it is not the only way. Let’s see:

a b a-b a-b-a a-b-a a-b-a-a a-b
1. Say a. (no way to say ab; replaying this action will say ab)
2. Say b. (no way to say ba; replaying this action will say ba)
3. Replay action 1. (says ab, no way to say aba; replaying this one will say aba)
4. Replay action 3. (says aba, no way to say abaa; replaying this one will say abaa)
5. Replay action 3. (says aba, although 4 would say abaa; replaying this one will say abaa
                     - the same as replaying 4! a wasted dictionary slot!)
6. Replay action 4. (says abaa, no way to say abaab; replaying this one will say abaab)
7. Replay action 1. (says ab. no way to say abEOF; the last one is never replayed,
                     but it would go aba or abb depending on what would be
                     the first letter of 8)

One action less! However, notice the note on step 5.

Okay, so back to flexiGIF. The thing done by it is flexible parsing. What this means is that the program does not immediately decide on a furthest-reaching action, but defers the decision until it knows what would be the furthest-reaching combination of two actions. Then it emits the first action, but still holds the second one for reassessment. This is called one-step lookahead. So basically still greedy, but now uses two actions.

In theory, it should be way better, and even optimal, but what happened on step 5 means there is now a wasted dictionary slot, and it is lost forever (at least until a reset happens). So this is why flexiGIF can give worse results. It fully gives up on greedy compression and sticks to ‘for each (sub)greedy match, find the greedy next match; emit the former’.

ZGIF

That’s where I needed to write my own thing. I was wondering, ‘how slow would it be to actually check all the possibilities?’ So I tried it and what have I found out? GLACIALLY SLOW. (Here I should note that Python is not the best choice for CPU-bound software. I want to take the opportunity to learn Zig.) It takes 4 minutes on my laptop to fully compress a 16x16 image. That’s 256 bytes uncompressed. And it takes several minutes. Wow.

I must be computing the same thing several times, right? (No, it’s just things that provide no improvements. The first version took 30 minutes.)

So I decided that there should be an option to make it just a little faster, by skipping all explorations that cannot be immediately extended beyond what’s currently best (uhm, limiting the search to 1-step lookahead). This worsens the results (does not find the actually best solution), but going from 4m down to 4s while still beating the current state-of-the-art is a win worth considering.

You can take a look at the ZGIF repository on SourceHut. The code is not in any way clean, but you can see my thought process in the Git history - going from A* to dynamic programming to a hybrid search with pruning.

Hope it is useful to you!