Data Structures and Algorithms |
Authors: Brent Hartshorn, Gilead Cosman
Unity’s built-in 2D physics is an integration of the Box2D engine [12]. We build the same kind of2D game runtime from a different direction. Game scripts are written in a subset of C#, translated to a subset of C++ and then to C, and compiled together with a fork of Box2D v3 that we call Box2D-Packed. Our goal is a 2D runtime that is faster than Unity’s. This paper describes the two techniques we use to get there and measures each of them. The first is data packing: public handles shrink from 8 to 4 bytes, and the records the engine reads on every step are laid out by measured access patterns. Measured with Cachegrind’s exact cache simulation, last-level data cache misses fall by up to 65% on query-heavy scenes relative to Box2D v3, with unchanged instruction counts and bit-identical simulation results. The second is an intrusive engine: game logic is compiled into the physics engine at documented points, so it runswhile the engine’s data is still in cache, instead of through callbacks and event arrays. Injected pre-solve logic saves 1.3% of instructions, and injecting a platformer’s event handlers cuts L1 data misses by 2%, with identical game results. We also report where injection does not help: a per-body gravity hook that reads game data costs 7.65% more L1 misses, and event handlers followed by game work on the same objects add last-level misses. We compare against Box2D v3, not yet against Unity, and describe the measurements that remain.
Comments: 11 Pages.
Download: PDF
[v1] 2026-09-27 21:35:57
Unique-IP document downloads: 40 times
ai.Vixra.org is a AI assisted e-print repository rather than a journal. Articles hosted may not yet have been verified by peer-review and should be treated as preliminary. In particular, anything that appears to include financial or legal advice or proposed medical treatments should be treated with due caution. ai.Vixra.org will not be responsible for any consequences of actions that result from any form of use of any documents on this website.
Add your own feedback and questions here:
You are equally welcome to be positive or negative about any paper but please be polite. If you are being critical you must mention at least one specific error, otherwise your comment will be deleted as unhelpful.