---
title: "Aquarium"
url: "https://brandengarrett.com/experiments/aquarium"
author: "Branden Garrett"
datePublished: "2026-11-05T19:44:57.564Z"
dateModified: "2026-11-08T01:55:00.466Z"
description: "A low-poly fish tank where the chemistry is the game: real species, sourced traits, and water that has to balance. I built it to learn how the browser, WebAssembly, and the machine work together."
---

# Aquarium

A low-poly fish tank where the chemistry is the game: real species, sourced traits, and water that has to balance. I built it to learn how the browser, WebAssembly, and the machine work together.

- Try it: [bgrrtt-aquarium.vercel.app](https://bgrrtt-aquarium.vercel.app)

## Why I built it

I wanted to find out who actually does the work in a browser: JavaScript, WebAssembly, worker threads, or the GPU. A fish tank gave that question a real job, because the interesting part is the water, and water chemistry is a real computation. I also suspected three.js on top of Next.js would carry too much overhead, so it's plain Vite and TypeScript.

## What I learned

- **WebAssembly didn't win.** I wrote the same flocking algorithm twice, in typed-array JavaScript and in WebAssembly, with bit-identical output. At 1,000 fish it took 0.19 ms per step in Node JS and 0.12 ms in Node WASM. In Chrome the order flipped: 0.18 ms for JS, 0.22 ms for WASM. At 50,000 fish both sat around 68 ms in Node. Repeat runs varied by tens of percent, so I call it a tie, and neither gain matters at aquarium scale. The tank itself runs no WASM.
- **The chemistry is cheap.** One simulated minute costs about 1.25 microseconds in Node, so a simulated year runs in about 0.65 seconds. It lives in a Web Worker, away from rendering. The whole tank with 10 fish holds 60 fps on an M1 Max at about 0.5 ms of main-thread JavaScript per frame and 39 draw calls.
- **Solve the real equation and behavior shows up on its own.** pH and free CO2 come from the carbonate charge balance every simulated minute, so buffering is emergent. The tests pin it to things fishkeepers know: distilled water near pH 5.6, ammonia then nitrite then nitrate during a cycle, oxygen swinging day to night, and nitrogen conserved within 0.5% over 90 days.
- **Sourcing the species broke my placeholders.** The first neon tetra weighed 1.5 g at purchase. FishBase's length-weight formula puts a store-size neon near 0.1 g, so its bioload was about 6x too high. For plants, most nutrient constants have no published value at all, so they're labeled as estimates. The GPU side isn't measured yet; every number above is CPU.

## How to help

- **Fishkeepers:** if you keep neon tetras, otocinclus, oscars, Thai micro crabs, Java fern, Vallisneria, or hornwort, tell me where the tank behaves wrong. Known gaps: I have no sourced minimum tank size for otocinclus or the crab, and I couldn't confirm which otocinclus species is usually sold.
- **Real tank data:** every rate constant is hand-tuned until it looked right. If you've logged a real tank (nitrate rise per week, pH swing from day to night, how fast a new tank cycles), send it and I'll fit against it.
- **Benchmarks:** run [the lab page](https://bgrrtt-aquarium.vercel.app/lab.html) and email me the table with your browser and hardware. My Chrome numbers were taken with DevTools open, which makes them suspect.
