What slowed down a 1,200-layer animation?
The rocket crossed the line on frame 92 in every run. In the original NewtonLab editor, I waited a median of 8.63 seconds to see it get there. After I changed how the engine counted contacts, I waited 4.62. To see whether the result would hold in a second scene, I built a moth out of 1,200 editable text layers and let its wings fall apart.
Experiment 1 · The rocket launch
I’m building NewtonLab, a 2D physics tool for motion design, with AI-assisted coding. Motion Boutique’s Newton 5 demo got me interested in what happens past 1,000 independent layers. In my first side-by-side, a rocket lifted off as letters fell around it. Watching the launch, I could barely tell which version was faster.
That observation changed the test. At liftoff, the letters had barely started touching. The code I had changed ran after the physics step, when the engine recorded how many other bodies each object was touching. To exercise it, I started both versions with the same pile already on the floor and gave the rocket the same path. An initial recorded test showed a 44.8% reduction in median time to the line. I then switched recording off and measured the editor’s own playback path. The table below reports those recording-free measurements.
What one frame was doing
Suppose A is touching B, and B is touching C. The frame needs three counts. A has one neighbour, B has two, and C has one. Two shapes on A can touch B at the same time; B still counts as one neighbour of A.
NewtonLab already had a table of body pairs. The original code read the whole table once for A, again for B, and again for C. It did that for every body on every frame. My change was to walk the table once per frame. For each pair still touching, I added one to the count at each end. When writing a body’s state, the engine could look up its count. I left the solver, gravity and motion paths alone.
Experiment 2 · Atlas Wings
The rocket test began with a pile. For the second test I wanted the audience to see a pile form. Motion Boutique’s calligram tutorial arranges more than 1,000 layers into a dragon’s head. I used the same visual idea to design Atlas Wings. The letters of METAMORPHOSIS form a moth. Its wingtips release first, then the rest of the letters drop and collect at the bottom of the frame. Motion Boutique’s calligram tutorial

What the editor actually measured
I ran both implementations on the same Windows PC (Intel Core i9-13900KF), alternating which version ran first. Each run started a fresh editor process. I used NewtonLab’s normal Play timer and native engine session with recording off, and timed completed repaints on an offscreen Qt viewport. The rocket interval ran from frame 30 to 92. Atlas Wings ran from frame 0 to 179. Its authored movie lasts six seconds at 30 fps.
| Scene and condition | Original median | Single-pass median | Pairs favouring single pass |
|---|---|---|---|
| Rocket · letters piled up | 8.63 s | 4.62 s | 6 of 6 |
| Rocket · collisions disabled | 8.52 s | 8.34 s | 1 of 4 |
| Atlas Wings · letters falling into a pile | 33.49 s | 26.34 s | 4 of 4 |
| Atlas Wings · collisions disabled | 12.96 s | 13.21 s | 2 of 4 |
The revised editor finished sooner in every paired run of both contact-heavy scenes. With collisions disabled, the advantage disappeared as a consistent pattern. Disabling collisions lets letters pass through the floor, which also changes what the renderer draws. Each row therefore compares the two implementations on matching motion. The difference between two rows includes more than the cost of counting contacts.
I also timed the native engine alone for all 180 Atlas Wings frames. Median engine time fell from 26.06 to 17.82 seconds with collisions enabled. With collisions disabled it was 6.82 and 6.85 seconds. This gave me a second way to check where the editor result came from.
The list grew even as the pile had fewer active contacts
One detail surprised me. At rocket launch, 3,332 body pairs were touching and 467 entries from earlier contacts were still in the table. By frame 92, active pairs had fallen to 3,006, while the number of inactive entries had risen to 2,331. A quieter-looking pile could leave the original code with a longer list to search.
I tested that detail separately. In a native counting benchmark, I held 1,200 body IDs and 300 active pairs fixed and added 2,400 inactive entries. The original counting step went from 1.81 to 15.03 milliseconds. The single-pass version went from 0.125 to 0.155 milliseconds. Those figures are medians for the counting step alone. Holding the active pairs fixed isolated the cost of retaining contact history.
Did the faster version still count correctly?
In the rocket scene I reconstructed each body’s neighbours from contact-begin and contact-end events, then compared that count with the value written in the frame. All 180,300 body-by-frame counts matched, including frames where a pair separated and touched again. That happened 616 times. Both editor workers also returned matching frame records across all 150 rocket frames. The event check still relies on the engine detecting the original contact.
For Atlas Wings, state and event hashes and the global contact count matched on all 180 frames across all eight engine runs within each condition. I also baked the animation back to After Effects, reopened it, and checked position and rotation for all 1,200 layers at four frames each.
What I’d test next
These runs establish a repeatable improvement on two contact-heavy scenes on one machine on one day. The percentage depends on the scene and the interval. My next test would compare this single pass with an index that keeps only active pairs, measuring memory and update cost when pairs separate and reconnect rapidly. I’d repeat the editor trials across days and on a second CPU before publishing a broader performance claim.
The next time a dense preview slows down in my editor, I’ll time the work of recording each frame alongside the work of solving it. In this case, there was enough repeated work after the solver to change how long I waited to see the very same animation.
Research background
- Guendelman, Bridson and Fedkiw’s 1,000-body stacking experiment provided background on dense contacts. Nonconvex Rigid Bodies with Stacking, SIGGRAPH 2003
- Erin Catto describes bodies as graph nodes and contacts as edges. That distinction helps explain why one active body pair contributes one neighbour to each end. Simulation Islands