---
title: "Dynamic Tree Improvements"
description: "Box2D's dynamic tree inserts a new proxy using a greedy, single-descent heuristic that approximates minimizing the surface area heuristic (SAH) instead of doing an exhaustive search, since incremental insertion is inherently greedy anyway."
url: "https://swe.quest/articles/dynamic-tree-improvements-db8f5926a23bef4f"
canonical: "https://box2d.org/posts/2025/03/dynamic-tree-improvements/"
source: "Box2D"
published: "2025-03-21"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 3
tags: ["data-structures","algorithms","gaming","c-cpp"]
---

# Dynamic Tree Improvements

A post on [Box2D](https://swe.quest/sources/box2d.md), published 2025-03-21, 3 min read, Deep dive. Original: [https://box2d.org/posts/2025/03/dynamic-tree-improvements/](https://box2d.org/posts/2025/03/dynamic-tree-improvements/)

## Summary

Box2D's dynamic tree inserts a new proxy using a greedy, single-descent heuristic that approximates minimizing the surface area heuristic (SAH) instead of doing an exhaustive search, since incremental insertion is inherently greedy anyway. At each internal node it compares the direct cost of making the current node the sibling (area of the union) plus an inherited cost accumulated from enlarging ancestors. It also computes an optimistic lower-bound cost for descending into each child. For internal children, that bound is inheritedCost + Area(Union(C, D)) + min(0, Area(D) - Area(C)), clamped so the child itself can still be chosen as the sibling.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Data structures](https://swe.quest/tags/data-structures.md) (Architecture & design)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)
- [Games](https://swe.quest/tags/gaming.md) (Domains)
- [C & C++](https://swe.quest/tags/c-cpp.md) (Languages)

## Prerequisites

- bounding volume hierarchies
- axis-aligned bounding boxes
- surface area heuristic

## Keywords

Box2D, dynamic AABB tree, surface area heuristic

## Related posts

- [Inscribed Spheres](https://swe.quest/articles/inscribed-spheres-119dd641a396418e.md): Box2D · 2026-09-29 · Hard · 14 min read · Games, Algorithms, Performance engineering, C & C++
  Inscribed spheres give a cheap upper bound on the separation achievable along any axis in the separating axis test (SAT): n·d − (rA + rB), where d joins the sphere centers.
- [Box2D 3.2](https://swe.quest/articles/box2d-3-2-6bf0b6359f7de39c.md): Box2D · 2026-10-18 · Easy · 2 min read · Games, Performance engineering, C & C++
  Box2D 3.2 runs roughly three times faster than 3.1, with the speedup broken down by source: contact recycling (~40%), solver algorithm refinement (~20%), AVX2 runtime dispatch (~15%), solver optimization (~10%) and broad-phase optimization (~10%), which compound multiplicatively.
- [SIMD for Collision](https://swe.quest/articles/simd-for-collision-0a426a9583188633.md): Box2D · 2026-07-18 · Hard · 5 min read · Performance engineering, Games, Algorithms, C & C++
  Box3D uses wide SIMD to speed up the edge-edge phase of the Separating Axis Test, testing one edge of hull A against four edges of hull B at once using structure-of-arrays data.
- [Astra Dynamic Chunks: How We Saved by Redesigning a Key Part of Astra](https://swe.quest/articles/astra-dynamic-chunks-how-we-saved-by-redesigning-a-key-part-of-astra-2ad19dfa88650f39.md): Slack Engineering · 2024-11-18 · Medium · 6 min read · Search, Cost optimization, Storage systems, Algorithms, Deployment
  Slack's Astra log search engine replaced fixed-size chunk slots on cache nodes with dynamically sized chunks, because undersized chunks wasted allocated disk space and oversized chunks from recovery tasks could overflow their slots.
- [Rope & SumTree](https://swe.quest/articles/rope-sumtree-f2c50a52279e3db4.md): Zed · 2024-04-23 · Medium · 22 min read · Data structures, Rust, Developer tools, Concurrency
  Zed represents buffer text with a rope rather than a string, because contiguous strings make mid-file inserts and deletes, line navigation and very large files expensive.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
