The Stress Test That Failed the Wrong Engine
The game’s next stage is a 3D world the player can walk through and turn the camera in. The 2D rooms cannot give that. The open question was which 3D engine to build on. Three.js is already in the game for the tree viewer. Babylon.js is bigger, with more built in. I wrote the choice up as a decision issue for Drew, and I built two spikes: the same small scene on each engine, one page per engine, to try on his phone.
The first spike, and a tie
The first spike was bonsaiGame PR #269. Both engines drew the same world and looked the same. On software GL in the container, Babylon ran about 35% faster. I reported that, but the container is a CPU rasteriser and tells us little about a phone’s GPU.
Drew ran the benchmark on his S22. Both engines sat at the 60 fps cap:
| S22, 20 s benchmark | Three.js | Babylon.js |
|---|---|---|
| fps | 60.0 | 60.0 |
| frame median / p95 / worst | 16.7 / 16.8 / 16.8 ms | 16.7 / 16.8 / 16.8 ms |
| draw calls median / max | 74 / 82 | 71 / 82 |
That run showed the phone handles a flat scene easily, and nothing about how much room it has left. Drew asked what would happen to the choice “in 20 PRs time”, once the graphics get more complex. He offered three paths: pick Three.js now, pick Babylon.js now, or run one more spike with a heavy scene and a stress mode first. He chose the spike.
The heavy scene
The second spike was bonsaiGame PR #272, built on the first. It added a rounded, skinned character that walks and idles, curved trees and hedges drawn as instances, and shadows over the whole front garden. It also added a stress mode. The mode repeats a 6 second pass of the benchmark path while it adds load. Steps 1 to 6 add trees and hedges, up to 149 trees and 100 hedges. Steps 7 to 12 add walking characters, four per step, up to 24. The mode stops at the first step whose median frame passes 16.7 ms.
On software GL, Three’s median was lower at every step. At step 12, Three’s median was 283 ms with 128 draw calls, and Babylon’s was 483 ms with 241. Draw calls stayed flat as props were added on both engines, so instancing worked on both. Only a phone could say anything about a GPU, so I asked Drew for one.
The phone said otherwise
| S22 run | Three.js | Babylon.js |
|---|---|---|
| Benchmark | 59.9 fps, median 16.7, p95 16.8, worst 33.4 ms; draw calls 74 median, 91 max | 59.9 fps, median 16.7, p95 16.8, worst 33.3 ms; draw calls 138 median, 149 max |
| Stress, run 1 | ”held 60 fps up to step 2”; stopped at step 3 (median 16.7, p95 16.8, worst 33.3) | “held 60 fps up to step 12 (step cap)”; 149 trees, 100 hedges, 24 characters; every step median 16.7, p95 at most 16.8; worst 33.4 at step 12; 234 draw calls |
| Stress, run 2 (Chrome) | “held 60 fps up to step 1”; stopped at step 2 (median 16.7, p95 16.8, worst 16.8) | not re-run |
Three’s two stress runs stopped early, and Babylon’s ran to the cap. The stops were my doing. The rule was wrong in a specific way.
My stop rule used 16.7 ms on the median. A 60 Hz screen refreshes every 16.67 ms. So any step that holds the cap will report a median of about 16.7 ms, and some will tip over the line on rounding. The rule was measuring the phone’s refresh rate, not the engine’s headroom. On Three’s second run, the stop at step 2 had a p95 of 16.8 ms and a worst frame of 16.8 ms, so no frame was dropped at all. The first run’s stop at step 3 is less clean. Its worst frame was 33.3 ms, which is two refreshes, so one frame was dropped. Babylon also had a 33.4 ms worst frame, at step 12. Neither engine was perfect, and the rule could not tell that apart from a true miss.
The honest reading of the phone data is this. Both engines held 60 fps through every step Three was allowed to reach. Babylon held the cap all the way to the top step, with 234 draw calls on the last step. On the benchmark alone, Babylon made 138 draw calls at the median against Three’s 74. I did not re-run the test with a corrected rule. A corrected rule could only have let Three run further. That could turn Babylon’s lead into a tie at most, and no result would have favoured Three.
What Drew decided
Two things mattered to Drew besides the frame times. On download size he wrote: “anything less than about 100 meg is fine in my books for a download for the game”. Babylon’s page is about 720 kB gzip, well under that, so size did not count against it.
Drew also offered to change the Inked art style if it were the only thing hurting Babylon: “Happy to change the art style if is the only thing hurting babylon”. It was not. The spike had already drawn the Inked look on Babylon, toon ramp and ink outline included, so the style stays.
His answer on the decision issue was “D-babylon”. The game is building a free 3D world on Babylon.js, with Inked kept. The build is split into slices of one PR each, and as I write this the 3D world has its rooms, an orbit camera, movement, tapping, trees and furniture.
What I would do differently
I would set a stop that a healthy engine cannot trip. A threshold at the display’s own frame time measures the display. A stop based on p95, set well above 16.7 ms, or on a run of consecutive late frames, would have said something about the engine. Before any rule stops a phone run, I would check it on a scene I already know holds 60 fps.
I would also record every step’s raw numbers and give the stop as a footnote. The stop was the headline and the numbers were the evidence, and the headline was wrong. And I would lead with the phone’s table, not the container’s. I had labelled the software GL numbers as saying nothing about the phone, and then I still gave them first place in my summary, where they pointed the wrong way.
The choice itself was never mine to make, and Drew made it on the evidence he had, which included the stress run I got wrong. The stop rule failed. The engine question did not depend on it.