From a Transistor Netlist to a KiCad Schematic: Redrawing the 6502

Handed a transistor-level schematic PDF of the 6502, the first instinct is to draw it. But trying that quickly reveals a hard fact: the PDF is vector art, not a netlist — you cannot reliably recover which wire connects to which net from it. So the starting point of this project isn’t drawing; it’s finding a trustworthy connectivity source: the visual6502 netlist. 1. What the netlist gives you visual6502 ships three datasets: ...

October 20, 2026 · 3 min · daviszhen

Implementing Git for Data on DuckDB (Part 4): Moving Metadata into Tables — Transactions, Crash Consistency and 'Hidden but Readable'

The first three posts were about features. This one is about the engineering of the metadata itself: where snapshots and branches are stored, and how they survive. 1. The problem: a metadata block is not transactional The first implementation wrote the reference registry (snapshots/branches/pins) into the checkpoint metadata block. It persisted, but had two fatal issues: Not in a transaction: if CREATE SNAPSHOT failed or rolled back, the block might already have been written; No WAL: if the process crashed before the next checkpoint, the change was gone. The actual requirement: reference changes must commit or roll back with the caller’s transaction, like ordinary data, and go through WAL replay. ...

October 20, 2026 · 4 min · daviszhen

Implementing Git for Data on DuckDB (Part 3): Branches, diff, pick, merge — The Version Primitives of Data

The first two posts made history readable. This one covers what makes a data version system actually useful: branches and changes. 1. The branch model A branch isn’t “a copy of the data”; it’s a combination of three things: branch = pin (which commit) + name + lineage (parent / base_line) + optional storage (materialized copy) or delta (changes relative to a base) materialize: really copy the table; reads go straight to the copy; delta: store only “which keys were removed from the base, which rows were added”; reads compose; update in a delta is a removal plus an addition of the same key (replacement pairing). This design brings the cost of “create a branch” from “copy a table” down to “register one metadata row.” ...

October 20, 2026 · 4 min · daviszhen

Implementing Git for Data on DuckDB (Part 2): Pinning History — Snapshots, Retention Watermarks and AT SNAPSHOT

The previous post argued that the counterintuitive gate is retention. This one takes it apart: two watermarks, one measurement, and making AT (SNAPSHOT => 'name') actually read. 1. Two watermarks DuckDB’s MVCC only answers “can this transaction see that row.” Supporting snapshots means separating two questions: Watermark Computed from Used for LowestVisibilityBound() Active transactions only Deciding which commits are “past”: releasing locks, cleaning transaction records LowestRetentionBound() min(active transactions, pinned snapshots) Deciding which historical versions must not be reclaimed We initially only had the first. The result: create a snapshot, run a checkpoint, and the old version is reclaimed anyway — because to checkpoint, there are no active transactions, so the old version is garbage. ...

October 20, 2026 · 3 min · daviszhen

Implementing Git for Data on DuckDB (Part 1): Feasibility — Why an Analytical Database Can Grow Version Control

Git gave code cheap rollbacks, parallel branches and merges. Data never got the same deal — because data is huge; one copy is a terabyte. But a trend is changing that: the people editing data are turning into AI clusters. Once scale and frequency go up an order of magnitude, branching, rollback and merge move from “nice feature” to “the only way this can be safe.” That’s the starting point of Git4Data. MatrixOne has already built these primitives into a database. My question: can DuckDB do the same? ...

October 20, 2026 · 3 min · daviszhen

Rewriting Lucene in C++ (Part 4): The Writer and the Long Tail — From 59% to 100% Coverage

The first three posts covered reading, scoring and searching. The last one covers writing: the index writer, and a more prosaic question — how much do you actually support? 1. Writer architecture In one sentence: documents come in, get grouped by term → token, accumulate in a RAM buffer, and flush into a segment when full. Design point Approach Why Grouping Reusable (termId, tokenIndex) integer sort Each term’s postings are written contiguously Encoding One varint stream per term: [docDelta, freq, posDelta*freq] Matches the Lucene104 format Segment names Base 36 Java’s rule; otherwise multi-segment naming collides Deleted bitmap .liv = header + bits2words(maxDoc) little-endian longs 1 = live; padding bits past maxDoc must be cleared Merge Pairwise merge tree (not whole-index reread) Bounded memory, output still equivalent to a single pass Append Pre-register source FieldInfos Preserves field numbers; otherwise they all shift 2. Acceptance: byte identity Merge and append correctness has a one-line criterion: ...

October 20, 2026 · 4 min · daviszhen

Rewriting Lucene in C++ (Part 3): From 128 to 592 QPS — The Search Performance Fight

The first two posts were about “is it right.” This one is about “is it fast” — and not a 10% difference, but 5x. 1. Baseline: 128 vs 634 QPS 1M docs, luceneutil task set, Top-10: Scale C++ Java 250K docs 483 QPS 1,886 QPS 1M docs 128 QPS 634 QPS The gap isn’t constant — it grows with data size, which means the bottleneck is the per-document processing path, not startup overhead. ...

October 20, 2026 · 4 min · daviszhen

Rewriting Lucene in C++ (Part 2): Bit-Exact Scoring — The Floating-Point Traps of BM25

The previous post covered format compatibility: an index Java can read and verify. This one covers the harder part — scores must be bit-exact. Why so strict? Because verification is reconciliation: the same queries must return the same Top-N documents and the same score bits. If a score differs by one ULP (unit in the last place), documents can swap places at the boundary, the reconciliation never lines up, and you lose your only source of truth. ...

October 20, 2026 · 4 min · daviszhen

Rewriting Lucene in C++ (Part 1): Byte-Level Compatibility — When Java Reads a C++-Written Index

The easiest way to go wrong when porting Lucene to C++ is to say: “I’ll invent my own index format, and just be self-consistent.” That works, but it has no verification standard: you can’t prove your implementation is correct, only that it agrees with itself. I chose the other path: byte-level compatibility. The goal is that Java Lucene 10.4 can read a C++-written index (CheckIndex OK), C++ can read a Java-written index, and the dumps from both sides are byte-for-byte identical. ...

October 20, 2026 · 3 min · daviszhen

Reading gporca (Part 3): The Key of a DP Cell — (Group, Required Properties, Stage)

The first two posts covered the framework mechanics and the scheduler. This one goes into the heart of the memo: the dynamic-programming cell. 1. Correcting an intuition Many people assume the optimizer’s job is to “find one optimal plan per group.” But gporca’s problem definition is: For each group, under the given requirements, find an optimal plan. Because the best implementation for the same group differs completely under different requirements: ...

October 20, 2026 · 4 min · daviszhen

Reading gporca (Part 2): The Reference-Count Gate That Turns Recursive Search into a Pausable Task Network

Query-optimizer search is inherently recursive: explore a group, derive plans, recurse into each input. The naive implementation is plain depth-first recursion. gporca doesn’t do that — it flattens the recursion into a task network, driven by a ready queue and a single reference counter. This post takes apart the most subtle piece: the m_ulpRefs reference-count gate. 1. m_ulpRefs is not a lifetime counter CJob::m_ulpRefs has three sources that must be read together: ...

October 20, 2026 · 4 min · daviszhen

Reading gporca (Part 1): Only ~11K of Its 400K Lines Are Actually Framework

gporca is Greenplum’s query optimizer: about 401K lines across 935 compilation units. Opening it for the first time is intimidating. But if you slice it by “is this a framework design decision?”, the part that is actually framework is under 10K lines. 1. Four libraries, four roles Many people assume libgpopt is the framework and the other three are “foundational components.” That’s imprecise. They are four different kinds of thing: ...

October 20, 2026 · 4 min · daviszhen

Six Real Traps in an Optimizer: Matching Results Don't Mean a Correct Plan

The previous two posts covered the port and the acceptance work. This one is only about traps — six real ones from the COLUMBIA + TPC-H project. What they have in common: everything looks fine until it isn’t. Trap 1: matching results, wrong plan The plan for ORDER BY ... LIMIT was once P_TOP at the root with QSORT below it — “truncate, then sort” — semantically wrong. It slipped past every automated check: at execution time DuckDB normalizes ORDER BY after LIMIT, so the results of this plan were byte-identical to the correct plan’s. ...

October 20, 2026 · 4 min · daviszhen

Making an Optimizer Run TPC-H: Lossless Conversion and Execution Reconciliation for 22 Queries

An optimizer is worth using when it can digest all 22 TPC-H queries — not when it can run a couple of toy examples. This post records how we took COLUMBIA (see the previous post) from “runs Chain2” to “handles the whole TPC-H suite.” 1. Principle: convert as-is, never rewrite for the optimizer The first step wasn’t code, it was rules: As-is conversion: no restructuring of TPC-H SQL to make the optimizer’s life easier; Record what’s unsupported: syntax the optimizer can’t express yet goes on a TODO list, never gets deleted from the query; Reconcilable: the conversion must be provably equivalent to the original. The value of this discipline only shows up later: it turns “capability gaps” into a quantified list instead of a vague pile of failures. ...

October 20, 2026 · 4 min · daviszhen

Porting a 1999 Cascades Optimizer to Modern C++: The COLUMBIA Story

If you want to hand-write a query optimizer, the cheapest starting point isn’t inventing one from scratch — it’s understanding a real Cascades implementation first, then getting it to run on your own machine. My sparring partner was COLUMBIA — the master’s thesis implementation by Yongwen Xu at Portland State University (1998–2000, advised by Shapiro and Maier), a textbook-grade Cascades/Volcano optimizer in 19,787 lines across 17 .cpp and 17 .h files. ...

October 20, 2026 · 4 min · daviszhen

Code Agents and FPGA Development: A 97-Round Experiment Log

Three CPU systems built from scratch on a 6,272-logic-element entry-level FPGA. This post records the whole process, quantifies the efficiency gains, and — most importantly — the traps the agent actually fell into. 1. Experimental Setup Hardware Item Value Board Entry-level Cyclone IV dev board Device EP4CE6F17C8 — 6,272 LE / 392 LAB / 30×M9K (276,480 bit) Clock 50 MHz Peripherals VGA (640×480@60), 32MB SDRAM, USB-UART, 4×LED, 4×buttons Programmer USB-Blaster compatible Toolchain (final form) Stage Tool Config / Role Synthesis & place-and-route Quartus Prime Lite 20.1.1 Running in a QEMU full-system x86-64 VM (Ubuntu 22.04); one build takes 230–530 s Logic simulation Verilator 5.052 --cc --exe --build --public; 2M cycles in about 0.5 s Flashing openFPGALoader ≥ 1.1.1 Over SSH on a separate Linux host; -c usb-blaster 6502 assembly cc65 2.19 (ca65 / ld65) -t none + custom NROM-128 linker script RISC-V build xPack riscv-none-elf-gcc 15.2.0 newlib included, builds NEORV32 firmware Version control git 14 commits, 5 hardware-verified bitstreams Three key choices and what they cost: ...

October 20, 2026 · 10 min · daviszhen

How to Find a Product Idea Worth Testing

Every builder I know has a list of product ideas. Almost none of them have a list of problems worth solving. The difference sounds semantic; it’s actually the whole game. Ideas are cheap — pain is the asset An idea is a solution in search of a problem. What you’re actually looking for is the reverse: a problem that already exists, hurts often, hurts enough, and has a budget attached. A useful filter is three questions: ...

October 20, 2025 · 3 min · daviszhen

The Minimal Business Loop

Strip away the pitch decks and every business reduces to a loop: attention → interest → commitment → revenue, with what you learn feeding back to the top. Most first attempts fail not because the idea is bad, but because nobody is measuring where the loop breaks. The four hops Attention. Someone discovers you exist. For this site: an essay that gets shared, a pick that gets clicked. Interest. They stay. They read a second page. They come back. Commitment. They give you something that costs them: an email, a reply, a waitlist slot. Revenue. They pay. The smallest possible payment counts more than the largest possible praise. Why commitment is the first number that matters Page views flatter you; emails don’t. A page view costs the visitor nothing and tells you almost nothing. An email address is microscopically small as transactions go, but it crosses the line from audience to lead — someone you can reach again without an algorithm’s permission. ...

October 19, 2025 · 3 min · daviszhen

Ship a Bilingual Site in One Day

digitalitem went from “no site” to “bilingual site with a working signup backend” in a day, on a $5-class VPS, with an entirely open-source stack. This post is the full blueprint — opinionated on purpose, because at the validation stage the best stack is the one that’s already running. The stack Hugo (Go) for the site itself — a single binary that turns Markdown into a fast static site. No database, no runtime, nothing to patch at midnight. PaperMod, a popular MIT-licensed theme — clean typography, dark mode, and built-in language switching. One small Go API (~150 lines, standard library only) for the single dynamic feature: newsletter signups and live counters, stored in a plain JSON-lines file you can back up by copying it. nginx in front: serves the static files, proxies /api/* to Go, picks your language from Accept-Language. systemd keeps the API alive. That’s the whole infrastructure. Bilingual as a first-class citizen i18n is done by content folders: content/en/… and content/zh/…. Every page has a mirrored counterpart, the language switcher is automatic, and the root URL redirects by browser language. Writing a bilingual post means writing two Markdown files — no translation framework, no key files. ...

October 18, 2025 · 3 min · daviszhen