Tombstone
vector-register
Dec 2014 โ Mar 2015 ยท age 32โ33
What it was
A 2D vector math library for Java that refuses to allocate. Clean vector classes put every vector on the heap and churn the garbage collector in hot loops; hand-inlined arithmetic is fast and unreadable. vector-register split the difference: a VectorRegisterN object holds N vectors as plain double fields, allocated once, and every operation between any of them is a generated method with the indices baked into its name, like sub_0_from_1 or transform_1_by_0_2. A generator emitted fifteen such classes, each extending the last so it only added what its newest vector needed, along with a full JUnit suite whose expected values were computed separately at generation time. Line intersection, point-in-triangle and polygon tests were built on top, all without a temporary object. It was written in ten days, then rolled into the 2D editor it was made for.
Wins, for the age
- At thirty-two, Jeff got struct-like performance out of a language with no structs, by naming indices into identifiers and letting the JIT see straight-line field arithmetic. Denied structs, the primate simply spelled them out.
- Generated the library and its tests from the same generator, with the tests computing their answers a different way, and that independent oracle caught a real matrix-inversion bug within a day.
- Used inheritance as deduplication, keeping the largest class near 5,700 lines instead of roughly 40,000.
- Benchmarked against the inlined floor, with warmup and averaging, before claiming speed in a readme. Most apes skip that part.
- Published to Maven Central, and reused that ceremony for every library afterward.
What it taught
- Generate code and its tests from one description, and make the tests reach the answer by another road.
- "100% coverage" is not correctness: the colinearity check still missed points on the opposite side.
- A benchmark must compare the same work. The immutable and register loops summed slightly different inputs; the conclusion held, the rigor did not.
- Generated documentation repeats every wording slip a thousand times.
Genealogy
Ancestors: Vec4U: vector algebra compiled into specialized code for speed. Descendants: Adama Core: code and tests generated from one description, at language scale.
Epitaph
Here lies vector-register: fifteen registers, eight hundred methods, no allocations. It found its own first bug with tests it wrote itself, then went to live inside the tool it was made for.