# Mastering Speed: Precompute for Instant Results! Newsy: Dev Concepts Weekly Published: 2025-12-02T14:00:00.495Z Source: https://newsyai.com/edition/dc8e5105-310f-4105-adf4-bbe8ef7da729 Archive: https://newsyai.com/newsy/249754d5-9f20-4825-9aeb-daeec7c365c9.md --- # The Pros Know the Fundamentals Better! Daily Edition — December 2, 2025 > “Great systems feel fast because the work happened before you asked.” Three high‑impact topics (about 90 seconds each) to compound your growth. Plain English, vivid metaphors, practical moves. --- ## 1) Precompute on Purpose: Move the Work to Yesterday Most “slow” software isn’t slow everywhere—it’s slow in the exact moment the user asks for something that’s expensive to calculate. Fix that by doing the heavy lifting ahead of time and serving prepared results. - Why it works - Latency drops because reads are cheap and predictable. - Spikes stop hurting; you’ve already done the math. - You trade occasional background cost for consistent user speed. - Metaphor - Think restaurant mise en place: the chopping and measuring happen before the orders roll in, so the dish flies out when requested. - How to do it 1. Identify hot questions, not hot queries: “What does the user see first?” “What powers search/autocomplete?” 2. Build “ready-to-serve” views: materialized summaries, leaderboards, denormalized read models. 3. Define freshness, not perfection: e.g., “within 60 seconds” is often plenty. 4. Update incrementally: process only what changed since the last run. 5. Verify quietly: background jobs compute checksums or counts and compare to the source—alert only on drift. - Try this today - Pick one page with a slow load. Write a small job that precomputes its answer every minute and stores it. Switch the page to read the precomputed result. --- ## 2) Table-Driven Design: Replace Branches with a Rulebook If your code reads like a choose‑your‑own‑adventure novel full of `if/else` twists, it’s time to swap storylines for a table. Encode rules as data, not sprawling logic. - Why it works - Fewer moving parts in your head: you scan a concise table instead of tracing branches. - Adding a case becomes adding a row, not editing logic in five places. - Testing shrinks to “does this row produce this outcome?” - Metaphor - It’s a scoreboard, not a referee’s monologue. The board states the rules; the game engine just looks them up. - How to do it 1. List the inputs and outputs that actually matter (the “columns” and “result”). 2. Start with a CSV/JSON table that maps inputs to results; load it at startup. 3. Keep evaluation dumb: one function reads a row and applies the outcome. 4. Put rule changes behind review like content, not code—product can own small tweaks safely. 5. Log “which row matched” so debugging is a glance, not a spelunk. - Try this today - Find one tangled eligibility/pricing/feature gate. Extract it into a tiny lookup table and a single evaluator function. Add a test per row. --- ## 3) Cancellation as a Feature: Make Stopping Safe and Fast Real systems need an “eject” button. Users change their minds, networks hiccup, jobs take too long. Systems that stop cleanly feel robust—and are far easier to operate. - Why it works - You prevent zombie work that burns money and locks resources. - Retries become safe because partial work is cleaned up. - Incidents are smaller: you can cut power to just the stuck part. - Metaphor - It’s a parachute, not a pause button. You don’t just stop falling—you land safely with gear intact. - How to do it 1. Design cooperative cancellation: every long task checks “should I stop?” between steps. 2. Use timeouts as contracts: “This call gets 3s; after that, bail.” 3. Hold resources with leases, not forever locks; expiration = automatic cleanup. 4. Make operations idempotent so cancel + retry can’t double‑charge or double‑send. 5. Emit “started / cancelled / cleaned‑up” events for visibility and audits. - Try this today - Pick one long‑running job (export, report, video process). Add a cancel endpoint, periodic “shouldStop” checks, and a cleanup step that runs on both failure and cancel. --- ### Quick Recap - Precompute the expensive parts so the user path is always light. - Turn branching into a rulebook: simpler to read, test, and change. - Treat cancellation as a first‑class feature so stopping is safe and fast. These habits compound into software that feels effortless: speedy by default, simple to modify, and calm under pressure.