<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged compression</title>
<link>https://coderlegion.com/tag/compression</link>
<description>Powered by Question2Answer</description>
<item>
<title>I Moved Our Team's Documents On-Premise — and the Filing Nightmare That Followed Taught Me Somethi</title>
<link>https://coderlegion.com/31510/moved-our-teams-documents-premise-and-the-filing-nightmare-that-followed-taught-somethi</link>
<description>&lt;p&gt;I've always been the person in the room who pushes back on &quot;just put it in the cloud.&quot; Not for ideological reasons, and certainly not because I enjoy being difficult. The reason was plain: our documents are the business. Client contracts, internal notes, financial records — the kind of material you would not want sitting in someone else's data center where you can't see it or pull it back. So when we stood up an on-premise, air-gapped document store, I was the one who championed it. Data sovereignty felt like the responsible call, and for a while I felt quietly vindicated.&lt;/p&gt;
&lt;p&gt;What I didn't expect was that pulling our files off the cloud would quietly surface a problem we had been sitting on for years. The cloud had been hiding it. Search was decent, sharing was one link, and nobody noticed how disorganized the underlying pile actually was. The moment everything lived on our own hardware and we had to manage it ourselves, the mess came out of hiding.&lt;/p&gt;
&lt;p&gt;This is the story of how I learned that &quot;keep it local&quot; is the right instinct but only half the job — and what the other half turned out to be.&lt;/p&gt;
&lt;h3 id=&quot;the-moment-it-got-personal&quot;&gt;The moment it got personal&lt;/h3&gt;
&lt;p&gt;I'm not a paranoid person by nature. But about a year before we moved, a vendor we used for a side project emailed to say they'd been acquired, and &quot;your data will migrate to the new parent company's systems.&quot; Nobody asked us. Nobody flagged which files moved or who could now see them. It worked out fine in the end, but it left a mark: I'd been trusting a third party with material I'd never get back cleanly. When our own leadership started talking about sovereignty, I was already sold.&lt;/p&gt;
&lt;p&gt;The irony is that going local fixed the trust problem and created an organization problem. We'd outsourced not just storage but the discipline of keeping things ordered. Take the outsourcing away and you finally meet the pile you'd been ignoring.&lt;/p&gt;
&lt;h3 id=&quot;the-numbers-that-annoyed-me&quot;&gt;The numbers that annoyed me&lt;/h3&gt;
&lt;p&gt;A 2025 knowledge-worker study stuck with me. Organizations without a knowledge-management program had employees spending an average of 8.5 hours a week just looking for information. Organizations with one got that down to 4.6 hours — about 3.9 hours saved per person per week. Scaled to 1,000 employees, that's roughly 98 full-time equivalents freed up. I read that and realized we were paying that tax twice: once when files lived in scattered cloud drives, and again after we brought them home, because none of the structure carried over and our local search was weaker than what we'd left behind.&lt;/p&gt;
&lt;p&gt;The second number hit closer to the wallet. A storage analysis firm found that somewhere between 60% and 70% of enterprise network-attached storage is untouched for more than 90 days, and it sits on the most expensive tier of primary storage. We were paying premium money to hoard files nobody opened. On-premise storage isn't free just because it's ours; the disk, the backup, the power, and the admin time all carry a cost, and most of ours was spent on cold data we'd never triaged.&lt;/p&gt;
&lt;h3 id=&quot;what-actually-broke&quot;&gt;What actually broke&lt;/h3&gt;
&lt;p&gt;It wasn't the hardware. It was the accumulation. Decades of files in mixed formats — PDFs, scanned receipts, Office docs, images, the occasional video — piled into folders no one maintained. In the cloud we'd learned to live with it because a good search box masked the disorder. On our own metal, the local tooling was thinner, and the little gaps (a missing preview here, a sluggish index there) made the whole pile feel fragile.&lt;/p&gt;
&lt;p&gt;The scariest part for a workplace is the archives. Historical records with signatures and official seals can't just be re-rendered on a whim. Lose the integrity of a signed document and you've got a compliance problem, not a formatting nitpick. When everything was in the cloud, we'd outsourced that risk to a vendor's promise. Bringing it home meant the risk was ours again — and we hadn't earned the right to hold it yet.&lt;/p&gt;
&lt;p&gt;There's also a quieter failure mode that nobody warns you about. The day you go air-gapped, every &quot;convenient&quot; feature that quietly phoned home stops working, and you discover how much of your old workflow depended on a service you no longer trust with the data. That's the point, of course. But it also means the local tooling has to do the heavy lifting, and most of it was built assuming a connection.&lt;/p&gt;
&lt;h3 id=&quot;the-three-step-fix-that-actually-worked&quot;&gt;The three-step fix that actually worked&lt;/h3&gt;
&lt;p&gt;I stopped treating this as &quot;adopt on-premise&quot; and started treating it as &quot;fix the document line.&quot; Three steps, in this order:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Compress first.&lt;/strong&gt; Shrinking the backlog reclaimed space and made everything faster to move, back up, and index. The key constraint for us: the job had to run entirely on the device. No uploading sensitive files to an external service to get them processed — that would defeat the entire point of going local. I used a local-first compressor that runs its whole pipeline on-device; if you're curious about the category, search the name and you'll find it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Classify next.&lt;/strong&gt; Instead of building folder trees I'd abandon, I let a tool sort files by content, tag them, and archive them through plain-language commands. A conversational file tool that understands &quot;move everything from last quarter's client into the archived folder and tag it confidential&quot; is worth more than any taxonomy I'd hand-design.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Search by meaning, not by filename.&lt;/strong&gt; Semantic search that finds a file from its contents beats remembering what I named it three years ago. Combine it with full-text and you stop relying on past-me's naming discipline.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;One tooling note, since people always ask: the on-device compressor I leaned on (SmartSlim, if you want to look it up) handled the major format families in a single pass and never shipped a byte off the machine. On air-gapped hardware that property matters more than any benchmark number, because there is literally no outbound path to abuse.&lt;/p&gt;
&lt;h3 id=&quot;the-week-i-learned-to-count-moving-parts&quot;&gt;The week I learned to count moving parts&lt;/h3&gt;
&lt;p&gt;Somewhere in the middle of the migration, I caught an update note from the tool's makers that stuck with me. Their PDF compression — the exact job I was running on our oldest, most fragile archives — used to lean on external third-party utilities stitched together under the hood. Apparently that's the common pattern in this category. It had recently been replaced by a compression engine built in-house, doing the whole job itself.&lt;/p&gt;
&lt;p&gt;Nothing about the feature list changed. What changed was the shape of the thing I had to trust. One less external component whose version schedule I don't control. One less compatibility surprise waiting for the worst week of the migration. One less vendor to chase when something behaves differently on our hardware than it did in the demo.&lt;/p&gt;
&lt;p&gt;I'll be honest: before this project, I would have skimmed past a note like that. But when you're the one signing off that an archive survived a move intact — seals in place, layouts untouched — &quot;fewer moving parts&quot; stops being a marketing phrase and becomes something you quietly count. Every external dependency in a processing chain is a small bet that someone else's software keeps behaving tomorrow the way it behaved today. On an isolated network, you don't get to re-roll that bet easily. I've started asking every tool we deploy the same question now: what parts of this did you build, and what parts did you borrow? The answers have been more revealing than any feature comparison.&lt;/p&gt;
&lt;h3 id=&quot;a-framework-for-choosing-not-a-sales-pitch&quot;&gt;A framework for choosing, not a sales pitch&lt;/h3&gt;
&lt;p&gt;If you're untangling the same knot, here's the generic checklist I wish someone had handed me. Score your options against it; don't trust a one-line &quot;runs locally&quot; claim:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Dimension &lt;/th&gt;&lt;th&gt;What to check &lt;/th&gt;&lt;th&gt;Common trap&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Deployment model &lt;/td&gt;&lt;td&gt;Truly on-device / air-gapped, no phone-home &lt;/td&gt;&lt;td&gt;&quot;Offline mode&quot; that still syncs metadata out&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Format coverage &lt;/td&gt;&lt;td&gt;PDF, scans, Office, images, audio/video &lt;/td&gt;&lt;td&gt;Drops signed documents or breaks their integrity&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Performance &lt;/td&gt;&lt;td&gt;Large-file throughput, concurrency &lt;/td&gt;&lt;td&gt;Single-threaded, stalls on big scans&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Compliance &lt;/td&gt;&lt;td&gt;Sensitive-data redaction, audit trail &lt;/td&gt;&lt;td&gt;No redaction, leak risk on shared stores&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Search &lt;/td&gt;&lt;td&gt;Semantic + full-text, fast index &lt;/td&gt;&lt;td&gt;Filename-only search that hides real content&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;the-part-nobody-tells-you&quot;&gt;The part nobody tells you&lt;/h3&gt;
&lt;p&gt;Keeping documents on-premise is the right call for a lot of organizations, especially ones that handle sensitive records. But don't expect the document problem to solve itself the day you unplug from the cloud. Compression, classification, and retrieval need to move together, or you'll just recreate the old mess on new hardware that you now own and must maintain.&lt;/p&gt;
&lt;p&gt;Pick one real department, run it end to end, and watch three numbers: compression ratio, time-to-find, and how long a knowledge base takes to stand up. That tells you more than any conference talk. The sovereignty win is real, but only if the files on the other side of the migration are actually findable — otherwise you've traded one kind of risk for a slower, more expensive version of the same problem.&lt;/p&gt;
&lt;p&gt;If I were advising a friend about to make this switch, I'd tell them to spend the first two weeks only on the backlog, not on new documents. New work always finds a home; it's the rotting archive that sinks you. Compress it, let a tool classify the obvious stuff, and resist the urge to build the perfect folder hierarchy on day one. Order emerges from use, not from a plan you'll abandon by Friday.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/31510/moved-our-teams-documents-premise-and-the-filing-nightmare-that-followed-taught-somethi</guid>
<pubDate>Sat, 17 Oct 2026 12:11:17 +0000</pubDate>
</item>
<item>
<title>Building a Private RAG Pipeline That Doesn't Leak Patient Data</title>
<link>https://coderlegion.com/31299/building-a-private-rag-pipeline-that-doesnt-leak-patient-data</link>
<description>&lt;p&gt;&lt;img src=&quot;http://&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;If you have ever wired up a retrieval-augmented generation system for a normal company, the healthcare version will feel familiar and then suddenly will not. The retrieval math is the same. The constraints are a different sport. This is a walk through how a private RAG pipeline for medical documents tends to get built, and where the engineering effort actually has to go — because the interesting problems are not in the vector store, they are upstream of it.&lt;/p&gt;
&lt;p&gt;A note before we start: I am describing an approach and the trade-offs, not a specific product. When I quote numbers, they are published benchmarks or third-party surveys, and I will say which is which.&lt;/p&gt;
&lt;h3 id=&quot;why-just-use-a-hosted-api-falls-over&quot;&gt;Why &quot;just use a hosted API&quot; falls over&lt;/h3&gt;
&lt;p&gt;The first instinct for a quick RAG demo is to push documents to a managed embedding and chat service. That works until the documents contain patient health information, unpublished trial data, or anything bound by rules about where data is allowed to live. For a hospital, a lot of material simply cannot step outside the intranet. So the entire pipeline — extraction, chunking, embedding, retrieval, and the model call — has to be able to run on machines you control.&lt;/p&gt;
&lt;p&gt;That single constraint reshapes the architecture. You are no longer picking a vendor endpoint. You are assembling a stack that can be air-gapped, audited, and proven to keep bytes inside the building.&lt;/p&gt;
&lt;h3 id=&quot;the-cold-data-problem-is-bigger-than-you-think&quot;&gt;The cold-data problem is bigger than you think&lt;/h3&gt;
&lt;p&gt;Before any of the AI work, there is a storage reality worth respecting. Komprise surveyed enterprise NAS environments and found that 60% to 70% of data had not been touched in over 90 days, yet it was still sitting on the most expensive primary storage tier. In a hospital this shows up as the imaging archive: once films are digitized, enormous volumes of DICOM sit almost never opened, while the storage bill climbs.&lt;/p&gt;
&lt;p&gt;If you sweep that cold, duplicated mass into a retrieval pipeline, two things happen. Retrieval gets slower because the index is bloated with near-dead material, and inference gets more expensive because you are paying to embed and re-read files nobody needed. The engineering lesson is mundane but important: a trim step before ingestion pays for itself many times over. Archive what should be archived, dedupe what is duplicated, and only then index.&lt;/p&gt;
&lt;h3 id=&quot;compression-is-a-first-class-stage-not-an-afterthought&quot;&gt;Compression is a first-class stage, not an afterthought&lt;/h3&gt;
&lt;p&gt;This is the part most RAG tutorials skip. Medical corpora are heavy — scanned pages, high-resolution images, long PDFs, OFD documents, audio, video. Feeding them raw means large embeddings, large context windows, and large bills.&lt;/p&gt;
&lt;p&gt;Document compression, run locally so nothing leaves the environment, changes the economics. A published benchmark I came across processed a 443-page OFD document end to end in 124 seconds, and measured image token cost down by 85.9% against the GPT-4o rate. The volume reductions in that class of tool tend to land in the 60% to 80% range across eight format families — PDF, images, video, audio, Office, OFD, scans, and similar. None of that touches the readability of the text; it is footprint, not content.&lt;/p&gt;
&lt;p&gt;The practical effect is twofold. First, retrieval gets cheaper because there is less to embed. Second, the model can actually read the file — a 443-page document that used to blow the context window becomes tractable. The &quot;compression&quot; label undersells it; what it really buys you is whether the model can read the thing at all, and whether you can afford to let it.&lt;/p&gt;
&lt;p&gt;One such pipeline I looked at, a RAG data engineering base, is built around a self-hosted engine rather than a call to someone else's API, which matters precisely because of the residency constraint above.&lt;/p&gt;
&lt;h3 id=&quot;the-six-stage-path-from-pile-to-trusted-knowledge&quot;&gt;The six-stage path from pile to trusted knowledge&lt;/h3&gt;
&lt;p&gt;The retrieval side is where the quiet engineering lives. A reasonable private RAG base breaks the work into stages rather than one giant &quot;ingest and hope&quot;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Cleaning&lt;/strong&gt; — strip boilerplate, fix encoding, normalize scanned pages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Chunking&lt;/strong&gt; — split by structure, not by arbitrary character counts, so a retrieved passage keeps its meaning.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sensitive-field detection and masking&lt;/strong&gt; — flag personal and health information before it is ever indexed. The better implementations cover a meaningful number of categories; the ones built for healthcare tend to detect on the order of 13 classes of sensitive fields (names, ID numbers, record numbers, family history, and so on), with masking that can be reversible or irreversible depending on policy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Deduplication&lt;/strong&gt; — collapse the near-duplicates that the cold-data problem created.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Vectorization&lt;/strong&gt; — embed on local hardware.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Retrieval with provenance&lt;/strong&gt; — return passages that point at a specific, version-correct source.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The reason this is staged rather than monolithic is that in medicine a confident answer citing the wrong version of a protocol is worse than no answer. Spending real effort on de-duplication, field-level masking, and provenance before anything reaches the vector store is what separates a system you can trust from a system that sounds convincing.&lt;/p&gt;
&lt;h3 id=&quot;why-masking-belongs-before-indexing&quot;&gt;Why masking belongs before indexing&lt;/h3&gt;
&lt;p&gt;A common mistake is to embed first and worry about privacy later. That inverts the risk. Once a sensitive field is inside an embedding or a chat context, &quot;removing&quot; it is fuzzy at best. The safer shape is to detect and mask during ingestion, so the index itself never contains what it should not. This is also where the audit trail matters: if a regulator asks what left the building, the honest answer should be &quot;nothing,&quot; backed by logs showing the masking step ran on every document.&lt;/p&gt;
&lt;h3 id=&quot;deployment-shape-and-the-domestic-os-wrinkle&quot;&gt;Deployment shape and the domestic-OS wrinkle&lt;/h3&gt;
&lt;p&gt;For hospitals already on a localized software track, deployment fit is a real gate. A pipeline that only runs on a narrow set of Western operating systems creates a second project just to get it installed. The private-deployment model that tends to work is one that drops the whole system inside the hospital network and supports domestic environments such as Kylin and UnionTech, so &quot;will it even run here&quot; stops being a meeting.&lt;/p&gt;
&lt;h3 id=&quot;a-framework-for-evaluating-any-such-solution&quot;&gt;A framework for evaluating any such solution&lt;/h3&gt;
&lt;p&gt;If you are comparing approaches — and you should compare approaches, not just vendors — these are the dimensions I would put on the table. None of this names a product; it is the checklist I wish more teams started from:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Dimension to evaluate &lt;/th&gt;&lt;th&gt;What to check&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Data residency and exit rules &lt;/td&gt;&lt;td&gt;Can the full pipeline run on-premise or air-gapped, with no byte leaving your network?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Sensitive-field handling &lt;/td&gt;&lt;td&gt;How many categories of PII/PHI can it detect and mask automatically before indexing?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Format coverage &lt;/td&gt;&lt;td&gt;Do your actual file types — scans, images, Office, OFD, DICOM, audio, video — work?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Volume reduction &lt;/td&gt;&lt;td&gt;What is the typical size reduction, and is legibility preserved?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Compute cost at scale &lt;/td&gt;&lt;td&gt;Embedding and retrieval cost per thousand pages as the corpus grows into the millions.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Retrieval accuracy &lt;/td&gt;&lt;td&gt;Is chunking structure-aware, and is provenance tracked so answers are traceable?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Auditability &lt;/td&gt;&lt;td&gt;Are ingestion, masking, and retrieval logged for compliance review?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Deployment fit &lt;/td&gt;&lt;td&gt;On-prem, air-gapped, and compatible with the operating systems you already run?&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;I have kept the wording relative on purpose. &quot;Steadier,&quot; &quot;lower long-term,&quot; &quot;broader coverage&quot; — none of that is a verdict, it is what to verify for your own corpus.&lt;/p&gt;
&lt;h3 id=&quot;the-part-worth-taking-home&quot;&gt;The part worth taking home&lt;/h3&gt;
&lt;p&gt;The model is the easy, well-trodden part of medical RAG. The hard part is everything before it: respecting that the data cannot leave, trimming the cold mass, compressing so the model can read it, and masking so the index is safe to query. Get those upstream stages right and the retrieval layer becomes almost boring — which, for a system handling patient data, is exactly the compliment you want to give it.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/31299/building-a-private-rag-pipeline-that-doesnt-leak-patient-data</guid>
<pubDate>Fri, 16 Oct 2026 07:30:13 +0000</pubDate>
</item>
<item>
<title>My AI assistant kept choking on huge PDFs. Here's what actually helped.</title>
<link>https://coderlegion.com/31128/my-ai-assistant-kept-choking-on-huge-pdfs-heres-what-actually-helped</link>
<description>&lt;p&gt;Maybe this is obvious to some of you but it drove me up the wall for weeks, so posting in case it helps someone else.&lt;/p&gt;
&lt;p&gt;I do a lot of contract and document work. My setup is basically an AI assistant that I talk to about files all day. The model is plenty smart. The problem was never the brain — it was the mouth being too full.&lt;/p&gt;
&lt;p&gt;I'd drop a 200-400 page PDF into the chat and ask it to pull out the key clauses. Half the time it would clearly miss the back third of the document. Sometimes it just timed out. Other times I'd look at the token usage and decide I'd rather do it by hand than pay to ship a whole scanned book into the context window. So I'd bail, open a separate compressor, run it, check it didn't nuke the pages, paste it back, and try again. Every single time I did that, I lost the thread of what I was actually trying to do.&lt;/p&gt;
&lt;p&gt;That exit-and-return loop is the real killer. It's not that compression is hard. It's that having to DO the compression manually, outside the conversation, kills the whole &quot;just talk to it&quot; advantage.&lt;/p&gt;
&lt;p&gt;What finally worked for me was stopping thinking of compression as my job and making it the assistant's job. There's a local service I found (it's an MCP thing — if you search &quot;compress-mcp&quot; you'll find it) where the agent just shrinks the file on a single instruction, on my own machine, and the data never leaves my network. I don't open another app. I just say &quot;compress this before you read it&quot; and it happens.&lt;/p&gt;
&lt;p&gt;A few things that surprised me:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The tokens thing is real and bigger than I expected. Images especially. A raw high-res scan is largely garbage pixels the model pays to ingest but doesn't need. Shrink ahead, then send, and the bill drops a lot. One measurement I saw put image token cost down around 85.9% on a GPT-4o basis after compressing. Not a magic number, but multiply that across a day of docs and it adds up fast.&lt;/li&gt;
&lt;li&gt;Local matters more than speed for me. I deal with contracts. I am not uploading those to some random SaaS to get them compressed. The fact that it runs here, on my box, with sensitive-stuff detection also local, is the reason I could use it at all. If it required a cloud upload, I'd have said no immediately.&lt;/li&gt;
&lt;li&gt;It removed a daily micro-annoyance, not a dramatic one. I had a 443-page tendering doc that always timed out raw. With local compress-ahead it processed end to end in about two minutes and then the assistant actually read the whole thing. Small win, but it's every day.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A broader thing I've been thinking about: IDC estimated document-related issues are like 21.3% of enterprise productivity loss, which they translated to ~$19,732 per info worker per year. That sounds made up until you live the &quot;it cut off again, re-send, re-read&quot; loop fifty times a week. The fix isn't a smarter model. It's removing the boring step that breaks your flow.&lt;/p&gt;
&lt;p&gt;One detail I didn't expect: once the assistant could prep its own input, I started trusting it with messier material. Before, I treated it like a finicky machine that might choke, so I'd pre-clean everything by hand. After, I just handed it the folder. That trust is the actual upgrade — more than any speed number. A tool you can throw a giant pile of files at without a second thought is doing its job.&lt;/p&gt;
&lt;p&gt;I also stopped building a &quot;don't put this in the chat&quot; list in my head. Because everything goes through the same local path and the sensitive check runs on-device, the privacy boundary holds by construction rather than by me remembering a rule. For a solo worker that's a relief; for a team it's the thing that lets people actually adopt the tool instead of quietly routing around it.&lt;/p&gt;
&lt;p&gt;If you're evaluating options, don't overthink it. Ask yourself: does the file ever contain something you wouldn't upload to a stranger's server? Do you process big docs often enough that manual compression became a chore? Are you building on an assistant rather than just chatting? If yes, a local, callable compression layer is worth a look. If you occasionally shrink the odd image for a group chat, your phone already does that and you don't need anything heavier.&lt;/p&gt;
&lt;p&gt;One framework I use to decide, in case it's useful:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Data residency: does the file stay local, and is sensitive detection on-device?&lt;/li&gt;
&lt;li&gt;Invocation: can the agent call it in plain language, or do you run it by hand?&lt;/li&gt;
&lt;li&gt;Integration cost: do you write glue per platform, or is there a standard protocol?&lt;/li&gt;
&lt;li&gt;Fit: high-frequency large/confidential files, or occasional light tasks?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Before this I tried the obvious stuff. I set up a hotfolder and a script that watched it and compressed anything dropped in. It worked, kind of, but it was yet another thing to maintain, and the assistant still couldn't trigger it mid-conversation. The local agent-callable version won out because it met the work where it already was. If you go the script route, fair enough, just know the friction is in the handoff, not the compression.&lt;/p&gt;
&lt;p&gt;Anyway, the point isn't the tool, it's the pattern: stop being the one who preps the file. Let the thing that's going to read it also shrink it. Do that locally and you stop worrying about where the bytes go. Simple change, outsized calm.&lt;/p&gt;
&lt;p&gt;I'm not affiliated with anything here, just a guy who got tired of fighting his own files. The shift from &quot;I compress, then the AI reads&quot; to &quot;the AI compresses, then reads&quot; sounds tiny and it's the single noticeable quality-of-life change in my workflow this year. If your assistant keeps choking on big PDFs, that's probably the seam to fix early.&lt;/p&gt;
&lt;p&gt;Anyway, hope this helps someone. Happy to answer questions about the fully local setup if people are curious, and if you've solved this a different way I'd genuinely like to hear it.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/31128/my-ai-assistant-kept-choking-on-huge-pdfs-heres-what-actually-helped</guid>
<pubDate>Thu, 15 Oct 2026 05:11:25 +0000</pubDate>
</item>
<item>
<title>The Mechanics of Compression: How 100GB Becomes 25GB</title>
<link>https://coderlegion.com/14657/the-mechanics-of-compression-how-100gb-becomes-25gb</link>
<description>
&lt;p&gt;&lt;img src=&quot;https://blog.ratnesh-maurya.com/images/blog/The-Mechanics-of-Compression-How-100GB-Becomes-25GB.png&quot; alt=&quot;The Mechanics of Compression: How 100GB Becomes 25GB&quot;&gt;&lt;/p&gt;&lt;h2 id=&quot;the-mechanics-of-compression-how-100gb-becomes-25gb&quot;&gt;The Mechanics of Compression: How 100GB Becomes 25GB&lt;/h2&gt;
&lt;p&gt;In an era of 4K streaming and massive cloud databases, we often take for granted that a 100GB backup can be shrunk down to 25GB. It isn&amp;rsquo;t magic&amp;mdash;and it isn&amp;rsquo;t just &amp;ldquo;squeezing&amp;rdquo; bits. It&amp;rsquo;s a careful process of spotting patterns, removing redundancy, and using mathematical shorthand so that the same information takes less space. This post explains how that works in plain terms, so you can understand what happens under the hood when you zip a folder or stream a video.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;1-the-core-idea-redundancy-is-waste&quot;&gt;1. The Core Idea: Redundancy Is Waste&lt;/h2&gt;
&lt;p&gt;At its heart, compression is about &lt;strong&gt;efficiency&lt;/strong&gt;. Most data is repetitive. The same words, phrases, or pixel patterns show up again and again. If the computer has already seen a pattern once, it doesn&amp;rsquo;t need to store it again in full&amp;mdash;it can refer back to it or describe it in fewer bits.&lt;/p&gt;
&lt;p&gt;Think of a recipe that says &amp;ldquo;add salt&amp;rdquo; five times. You could write &amp;ldquo;add salt&amp;rdquo; five times, or you could write &amp;ldquo;add salt (&amp;times;5).&amp;rdquo; The second version carries the same information in less space. Compression algorithms do something similar: they find repetition and describe it more compactly.&lt;/p&gt;
&lt;p&gt;So the main job of any compression scheme is to &lt;strong&gt;find redundancy&lt;/strong&gt; and &lt;strong&gt;encode it in fewer bits&lt;/strong&gt; without losing the ability to recover the original data when needed.&lt;/p&gt;
&lt;h3 id=&quot;a-real-life-example-compressing-a-book-with-repeated-words&quot;&gt;A Real-Life Example: Compressing a Book with Repeated Words&lt;/h3&gt;
&lt;p&gt;Imagine a &lt;strong&gt;book&lt;/strong&gt; where the same words appear again and again. Words like &quot;the,&quot; &quot;and,&quot; and &quot;to&quot; might show up thousands of times. Instead of writing the full word every time, we could agree on a &lt;strong&gt;legend&lt;/strong&gt; at the start and replace each repeated word with a short &lt;strong&gt;sub-symbol&lt;/strong&gt;. Anyone with the legend can reconstruct the original text exactly.&lt;/p&gt;
&lt;p&gt;Suppose we define a small dictionary at the top of the page:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;hljs language-text&quot;&gt;Legend:  @ = the   |   # = and   |   % = to   |   &amp;sect; = of
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now take a normal sentence and &quot;compress&quot; it by substituting:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Original (longer):&lt;/strong&gt;
&quot;The king and the queen went to the castle and stayed there for the rest of the day.&quot;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Compressed (shorter):&lt;/strong&gt;
&quot;@ king # @ queen went % @ castle # stayed there for @ rest &amp;sect; @ day.&quot;&lt;/p&gt;
&lt;p&gt;We still have the same meaning, but we used one character (@, #, %, &amp;sect;) wherever a repeated word appeared. The &lt;strong&gt;legend&lt;/strong&gt; is the &quot;dictionary&quot;&amp;mdash;it has to be stored or sent once so the reader can decode. For a whole book, if &quot;the&quot; appears 2,000 times, we save (3 &amp;minus; 1) &amp;times; 2,000 = 4,000 characters just on that one word. Add &quot;and,&quot; &quot;to,&quot; &quot;of,&quot; and other frequent words, and the book shrinks noticeably without losing a single word.&lt;/p&gt;
&lt;p&gt;This is exactly the idea behind &lt;strong&gt;dictionary coding&lt;/strong&gt; and &lt;strong&gt;Huffman-style&lt;/strong&gt; compression: find what repeats, assign it a short code, and use that code everywhere. Real compressors do this automatically; they don't need a human to write the legend.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A real experiment from the wild:&lt;/strong&gt; Researchers applied this idea to the full text of &lt;strong&gt;&quot;Alice's Adventures in Wonderland&quot;&lt;/strong&gt; by Lewis Carroll. They treated each &lt;em&gt;word&lt;/em&gt; as a symbol, counted how often it appeared, and assigned &lt;strong&gt;shorter codes to the most frequent words&lt;/strong&gt; (like &quot;the,&quot; &quot;and,&quot; &quot;to,&quot; &quot;a&quot;) and &lt;strong&gt;longer codes to rare words&lt;/strong&gt; (like &quot;wretched,&quot; &quot;yawned&quot;). The result: the text went from &lt;strong&gt;164 KB down to 109 KB&lt;/strong&gt;&amp;mdash;about &lt;strong&gt;one-third smaller&lt;/strong&gt;&amp;mdash;with no information lost (&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.nayuki.io/page/huffman-coding-english-words&quot;&gt;&lt;em&gt;Huffman-coding English words&lt;/em&gt;&lt;/a&gt;, Project Nayuki&amp;mdash;includes original text from Project Gutenberg, input/output file sizes, and codebook samples). The same technique&amp;mdash;replace repeated words with shorter symbols, and keep a mapping so we can decode&amp;mdash;is what powers the compression we use every day in ZIP files and beyond.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;2-lossless-vs-lossy-two-different-goals&quot;&gt;2. Lossless vs. Lossy: Two Different Goals&lt;/h2&gt;
&lt;p&gt;Before diving into algorithms, it helps to know that compression splits into two families: &lt;strong&gt;lossless&lt;/strong&gt; and &lt;strong&gt;lossy&lt;/strong&gt;. The choice depends on whether you can afford to lose any information.&lt;/p&gt;
&lt;h3 id=&quot;lossless-compression-every-bit-preserved&quot;&gt;Lossless Compression: Every Bit Preserved&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Lossless&lt;/strong&gt; compression means that after you decompress, you get back &lt;strong&gt;exactly&lt;/strong&gt; the original data&amp;mdash;every bit. Nothing is discarded.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How it works:&lt;/strong&gt; The algorithm finds statistical redundancy (repeated or predictable patterns) and encodes them more efficiently. Decompression reverses the process and reconstructs the original stream.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;When to use it:&lt;/strong&gt; Whenever you cannot afford to lose information&amp;mdash;source code, text files, databases, executables, legal documents, medical data, or images where every pixel must stay exact (e.g. PNG for graphics, FLAC for audio).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Common formats:&lt;/strong&gt; ZIP, GZIP, PNG, GIF (for lossless use), FLAC.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So when you compress 100GB of source code or logs to 25GB with a lossless tool, you can later decompress and get back the same 100GB bit-for-bit.&lt;/p&gt;
&lt;h3 id=&quot;lossy-compression-smaller-files-imperceptible-loss&quot;&gt;Lossy Compression: Smaller Files, Imperceptible Loss&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Lossy&lt;/strong&gt; compression &lt;strong&gt;discards&lt;/strong&gt; some information on purpose. What you get back is an &lt;strong&gt;approximation&lt;/strong&gt; of the original&amp;mdash;close enough for human perception, but not identical.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;How it works:&lt;/strong&gt; The algorithm keeps what matters for the intended use (e.g. what the eye or ear notices) and drops &amp;ldquo;invisible&amp;rdquo; or less important detail&amp;mdash;e.g. colors we can&amp;rsquo;t easily tell apart, or sounds masked by louder ones.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;When to use it:&lt;/strong&gt; Media where small quality loss is acceptable&amp;mdash;photos (JPEG), music (MP3, AAC), video (H.264, VP9). Streaming and storage would be far heavier without lossy compression.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Common formats:&lt;/strong&gt; JPEG, MP3, AAC, H.264, VP9.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For the rest of this post we focus on &lt;strong&gt;lossless&lt;/strong&gt; compression&amp;mdash;the kind that powers ZIP, GZIP, and the 100GB&amp;rarr;25GB backup scenario&amp;mdash;and then briefly touch how &lt;strong&gt;video&lt;/strong&gt; combines similar ideas with lossy temporal compression.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;3-the-building-blocks-huffman-coding-and-lz77&quot;&gt;3. The Building Blocks: Huffman Coding and LZ77&lt;/h2&gt;
&lt;p&gt;Most modern lossless compressors (including the ones inside ZIP and GZIP) combine two ideas:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Dictionary / back-reference coding&lt;/strong&gt; (e.g. LZ77): &amp;ldquo;I&amp;rsquo;ve seen this phrase before; refer back to it.&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Entropy coding&lt;/strong&gt; (e.g. Huffman): &amp;ldquo;Frequent symbols get short codes; rare symbols get longer codes.&amp;rdquo;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Together they form algorithms like &lt;strong&gt;DEFLATE&lt;/strong&gt; (used in ZIP and GZIP): first reduce repetition with something like LZ77, then shorten the remaining stream with Huffman (or similar) coding.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;31-huffman-coding-short-codes-for-common-symbols&quot;&gt;3.1 Huffman Coding: Short Codes for Common Symbols&lt;/h3&gt;
&lt;p&gt;In normal text encoding (e.g. ASCII or UTF-8), every character uses the &lt;strong&gt;same&lt;/strong&gt; number of bits (e.g. 8 bits per character). So the letter &amp;ldquo;E&amp;rdquo; and the letter &amp;ldquo;Z&amp;rdquo; both cost 8 bits, even though &amp;ldquo;E&amp;rdquo; appears far more often in English text. That&amp;rsquo;s wasteful: we&amp;rsquo;re spending the same budget on rare and common symbols.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Huffman coding&lt;/strong&gt; fixes that by giving &lt;strong&gt;variable-length&lt;/strong&gt; codes: frequent symbols get &lt;strong&gt;shorter&lt;/strong&gt; codes, rare symbols get &lt;strong&gt;longer&lt;/strong&gt; codes. On average, the whole message uses fewer bits.&lt;/p&gt;
&lt;p&gt;One crucial constraint: no code is allowed to be a &lt;strong&gt;prefix&lt;/strong&gt; of another. So if &amp;ldquo;E&amp;rdquo; is encoded as &lt;code&gt;10&lt;/code&gt;, then no other character&amp;rsquo;s code can start with &lt;code&gt;10&lt;/code&gt; (e.g. no &lt;code&gt;100&lt;/code&gt; or &lt;code&gt;101&lt;/code&gt;). That way, when we read the compressed stream left-to-right, we always know where one symbol ends and the next begins&amp;mdash;no need for extra separators (unlike Morse code, which needs pauses between letters).&lt;/p&gt;
&lt;p&gt;A simple way to build such codes is with a &lt;strong&gt;binary tree&lt;/strong&gt;: each character is a leaf, and the path from the root to that leaf (e.g. left=0, right=1) is its code. The algorithm builds the tree from the &lt;strong&gt;bottom up&lt;/strong&gt;, repeatedly grouping the two least frequent symbols (or groups) until everything is in one tree. Frequent characters end up near the root (short path); rare ones end up deeper (long path).&lt;/p&gt;
&lt;p&gt;Conceptually:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;hljs language-text&quot;&gt;// Standard 8-bit encoding (e.g. ASCII): every character uses 8 bits
&quot;E&quot; = 01000101 (8 bits)
&quot;Z&quot; = 01011010 (8 bits)

// Huffman encoding (example): frequent letters get shorter codes
&quot;E&quot; = 10      (2 bits)   &amp;larr; common in English
&quot;Z&quot; = 111010  (6 bits)   &amp;larr; rare, so longer code
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So Huffman doesn&amp;rsquo;t &amp;ldquo;invent&amp;rdquo; new information; it &lt;strong&gt;represents&lt;/strong&gt; the same information in fewer bits by exploiting how often each symbol appears.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;32-lz77-ive-seen-this-beforepoint-back-to-it&quot;&gt;3.2 LZ77: &amp;ldquo;I&amp;rsquo;ve Seen This Before&amp;mdash;Point Back to It&amp;rdquo;&lt;/h3&gt;
&lt;p&gt;Huffman only shortens symbols based on frequency. It doesn&amp;rsquo;t remove &lt;strong&gt;repeated phrases&lt;/strong&gt;. That&amp;rsquo;s where &lt;strong&gt;LZ77&lt;/strong&gt; (and family) comes in.&lt;/p&gt;
&lt;p&gt;LZ77 keeps a &lt;strong&gt;sliding window&lt;/strong&gt; of recently seen data. As it reads the input, it looks for the &lt;strong&gt;longest match&lt;/strong&gt; between:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;what&amp;rsquo;s coming next (the &amp;ldquo;look-ahead&amp;rdquo; buffer), and&lt;/li&gt;
&lt;li&gt;what it has already seen (the &amp;ldquo;search&amp;rdquo; buffer).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When it finds a match, it doesn&amp;rsquo;t output the phrase again. Instead it outputs a &lt;strong&gt;back-reference&lt;/strong&gt;: a pair &lt;strong&gt;(distance, length)&lt;/strong&gt; meaning &amp;ldquo;go back &lt;code&gt;distance&lt;/code&gt; bytes and copy &lt;code&gt;length&lt;/code&gt; bytes.&amp;rdquo; The decoder can then reconstruct the phrase from earlier in the stream.&lt;/p&gt;
&lt;p&gt;So the stream becomes a mix of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Literal&lt;/strong&gt; bytes (when there&amp;rsquo;s no useful match), and&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Back-references&lt;/strong&gt; (when a phrase repeats).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;hljs language-text&quot;&gt;Input:  &quot;The quick brown fox jumps over the quick dog&quot;
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        &quot;the quick&quot; appears twice

Compressed idea:
  Literals: &quot;The quick brown fox jumps over &quot;
  Back-reference: (distance=31, length=9)  &amp;rarr; copy 9 bytes from 31 bytes ago
  Literals: &quot; dog&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After this step, the stream has fewer bytes but still contains the same information. Then Huffman (or similar) is applied to that stream to shorten the representation of literals and back-reference pairs&amp;mdash;that&amp;rsquo;s DEFLATE in a nutshell.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;4-zip-vs-targz-same-ideas-different-packaging&quot;&gt;4. ZIP vs. TAR.GZ: Same Ideas, Different Packaging&lt;/h2&gt;
&lt;p&gt;Both ZIP and TAR.GZ use lossless compression (often DEFLATE/GZIP-style), but they &lt;strong&gt;package&lt;/strong&gt; files differently. That difference affects compression ratio and how you can access files.&lt;/p&gt;
&lt;h3 id=&quot;zip-one-file-at-a-time&quot;&gt;ZIP: One File at a Time&lt;/h3&gt;
&lt;p&gt;ZIP compresses &lt;strong&gt;each file separately&lt;/strong&gt; and then puts them in one archive, with a central directory so you can list and extract individual files.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Pros:&lt;/strong&gt; &lt;strong&gt;Random access.&lt;/strong&gt; You can extract &lt;code&gt;image_402.jpg&lt;/code&gt; from a 50GB archive without reading or decompressing the rest. Good for browsing and pulling single files.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cons:&lt;/strong&gt; The compressor never looks &lt;strong&gt;across&lt;/strong&gt; file boundaries. If 100 files are nearly identical, ZIP may store 100 separate compressed versions and miss shared patterns. So total size can be larger than a &amp;ldquo;solid&amp;rdquo; archive.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So ZIP is great when you need &lt;strong&gt;per-file access&lt;/strong&gt; and broad compatibility (e.g. Windows, macOS, Linux).&lt;/p&gt;
&lt;h3 id=&quot;targz-one-big-stream-solid-archive&quot;&gt;TAR.GZ: One Big Stream (Solid Archive)&lt;/h3&gt;
&lt;p&gt;TAR.GZ is a &lt;strong&gt;two-step&lt;/strong&gt; process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;TAR (Tape Archiver):&lt;/strong&gt; Concatenate all files into one continuous &lt;strong&gt;stream&lt;/strong&gt; (no compression yet). This is a &amp;ldquo;solid&amp;rdquo; archive&amp;mdash;one long byte stream.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GZIP:&lt;/strong&gt; Compress that &lt;strong&gt;entire&lt;/strong&gt; stream with DEFLATE (LZ77 + Huffman) as if it were a single file.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Because GZIP sees the whole project as one stream, it can find patterns that span &lt;strong&gt;many files&lt;/strong&gt;. A repeated header in &lt;code&gt;file_A.txt&lt;/code&gt; can be used to compress the same header in &lt;code&gt;file_Z.txt&lt;/code&gt;. That&amp;rsquo;s why you can get a &lt;strong&gt;much&lt;/strong&gt; better ratio&amp;mdash;e.g. 100GB down to 25GB&amp;mdash;when you have lots of similar or repeated content across files.&lt;/p&gt;
&lt;p&gt;Trade-off: to get &lt;strong&gt;any&lt;/strong&gt; file out of a TAR.GZ, you typically have to decompress from the beginning up to that file. There&amp;rsquo;s no cheap &amp;ldquo;jump to file 402&amp;rdquo; as in ZIP.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;hljs language-bash&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Step 1: Bundle everything into one stream (size unchanged)&lt;/span&gt;
tar -cvf backup.tar ./my_project

&lt;span class=&quot;hljs-comment&quot;&gt;# Step 2: Compress that whole stream&lt;/span&gt;
gzip backup.tar

&lt;span class=&quot;hljs-comment&quot;&gt;# Result: backup.tar.gz &amp;mdash; one compressed stream&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;When to use TAR.GZ:&lt;/strong&gt; Backups, source tarballs, logs, or any case where you want &lt;strong&gt;maximum compression&lt;/strong&gt; and usually extract the whole archive (or don&amp;rsquo;t mind decompressing from the start to reach a file). Common on Linux and in DevOps pipelines.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When to prefer ZIP:&lt;/strong&gt; When you need &lt;strong&gt;random access&lt;/strong&gt; to individual files or maximum compatibility with non-Unix systems.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;5-how-video-compression-goes-further-temporal-redundancy&quot;&gt;5. How Video Compression Goes Further: Temporal Redundancy&lt;/h2&gt;
&lt;p&gt;Video has a special kind of redundancy: &lt;strong&gt;between frames&lt;/strong&gt;, most of the image doesn&amp;rsquo;t change. Only moving parts (and lighting changes) differ. So instead of storing every frame in full, modern codecs (e.g. H.264) use &lt;strong&gt;temporal compression&lt;/strong&gt;: store one full frame, then for the next frames store mainly &lt;strong&gt;what changed&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Roughly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;I-frames (Intra-frames):&lt;/strong&gt; Full frames&amp;mdash;like a JPEG image. They don&amp;rsquo;t depend on other frames. Used as anchors so you can seek or recover from errors.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;P-frames (Predictive):&lt;/strong&gt; Encoded as &amp;ldquo;differences&amp;rdquo; from a previous frame (or I-frame). Much smaller than a full frame.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;B-frames (Bi-predictive):&lt;/strong&gt; Use both past and future frames to predict the current frame, so they can be even smaller.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So conceptually:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;hljs language-text&quot;&gt;Frame 1 (I):  Full image of a sunset
Frame 2 (P):  &amp;ldquo;Same as Frame 1, but the bird moved 2 pixels left&amp;rdquo;
Frame 3 (P):  &amp;ldquo;Same as Frame 2, but the bird moved 2 pixels left&amp;rdquo;
&amp;hellip;
Total stored: one full frame + many small &amp;ldquo;deltas&amp;rdquo; and motion vectors
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://blog.ratnesh-maurya.com/images/blogs-inline-image/inter-frame-prediction-video-compression.png&quot; alt=&quot;Inter-frame prediction: I-frame and P-frames with motion vectors. Frame 1 is a full photo; Frames 2 and 3 store only the moving bird and motion vector (-2, 0).&quot;&gt;&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s &lt;strong&gt;temporal&lt;/strong&gt; compression. Video also uses &lt;strong&gt;spatial&lt;/strong&gt; compression inside each frame (similar in spirit to JPEG). Together, temporal + spatial (and often lossy choices) let streaming and storage stay practical at 1080p and 4K.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;6-wrapping-up&quot;&gt;6. Wrapping Up&lt;/h2&gt;
&lt;p&gt;Compression is the invisible engine behind smaller backups, faster transfers, and watchable video. The main ideas are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Redundancy&lt;/strong&gt; is removed or shortened: repeated phrases become back-references (LZ77), and frequent symbols get short codes (Huffman).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lossless&lt;/strong&gt; (ZIP, GZIP, PNG) keeps every bit; &lt;strong&gt;lossy&lt;/strong&gt; (JPEG, MP3, H.264) trades a bit of quality for much smaller size.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ZIP&lt;/strong&gt; compresses file-by-file for random access; &lt;strong&gt;TAR.GZ&lt;/strong&gt; compresses one solid stream for better ratio when you don&amp;rsquo;t need per-file random access.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Video&lt;/strong&gt; adds &lt;strong&gt;temporal&lt;/strong&gt; compression: store full frames rarely, and mostly store changes between frames.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Understanding these mechanics helps you choose the right format&amp;mdash;whether you&amp;rsquo;re optimizing Next.js assets, shipping backups to S3, or tuning video encoding&amp;mdash;and demystifies how 100GB can become 25GB without losing a single bit.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;written using AI tools&lt;/p&gt;
&lt;/blockquote&gt;
</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/14657/the-mechanics-of-compression-how-100gb-becomes-25gb</guid>
<pubDate>Sun, 19 Apr 2026 23:55:52 +0000</pubDate>
</item>
</channel>
</rss>