Skip to content

Commit 99fddf3

Browse files
docs: expand README with detailed performance explanations
Add code examples showing zero-allocation getter pattern and explain why the fork is faster (latest Rapier, optimized WASM boundary). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 525cbeb commit 99fddf3

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

README.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626

2727
## Fork Differences
2828

29-
This is a fork of [@dimforge/rapier.js](https://github.com/dimforge/rapier.js) with:
29+
This is a fork of [@dimforge/rapier.js](https://github.com/dimforge/rapier.js) with performance improvements and modernized tooling.
3030

31-
- Rapier 0.32 with glam math library
32-
- pnpm monorepo with tsdown bundler
33-
- Zero-allocation getters (optional target parameter)
34-
- Built-in benchmarks
35-
- Simplified package variants (4 per dimension)
31+
### Why This Fork?
32+
33+
1. **Latest Rapier**: Rapier 0.32 (official npm is on 0.29)
34+
2. **Zero-allocation getters**: Optional `target` parameter avoids object creation in hot paths
35+
3. **Optimized WASM boundary**: Ray casting passes primitives directly instead of temporary WASM objects
36+
4. **Modern build**: pnpm monorepo, tsdown bundler, smaller bundles
3637

3738
### Benchmarks vs Official
3839

@@ -46,11 +47,34 @@ Comparison against `@dimforge/rapier3d-compat@0.19.3` (3D, 1000 bodies):
4647
| body.translation() | 73µs | 210µs | **2.9x** |
4748
| body.rotation() | 70µs | 223µs | **3.2x** |
4849

49-
Key improvements:
50+
### What Makes It Faster
51+
52+
**Zero-allocation getters (3x faster)**
53+
54+
The official package allocates a new object every call:
55+
56+
```typescript
57+
// Official: allocates {x, y, z} every call
58+
for (const body of bodies) {
59+
const pos = body.translation(); // new object
60+
}
61+
```
62+
63+
This fork accepts an optional target to reuse:
64+
65+
```typescript
66+
// Fork: zero allocations
67+
const pos = {x: 0, y: 0, z: 0};
68+
for (const body of bodies) {
69+
body.translation(pos); // writes into existing object
70+
}
71+
```
72+
73+
Supported: `translation()`, `rotation()`, `linvel()`, `angvel()`, `nextTranslation()`, `nextRotation()`, `localCom()`, `worldCom()`
74+
75+
**Optimized ray casting (35% faster)**
5076

51-
- **Getters**: 3x faster (zero-allocation optimization)
52-
- **Ray casting**: 35% faster (primitives passed directly to WASM)
53-
- **Body creation**: 7% faster
77+
Ray origin/direction passed as primitives directly to WASM, avoiding temporary `RawVector` allocations.
5478

5579
Run `pnpm bench --official` to compare on your machine.
5680

0 commit comments

Comments
 (0)