Godot
The GodotBench sample runs the same GDScript file twice in a Godot project: once in Godot's GDScript VM and once compiled by Typhon into the project's C# assembly.
samples/GodotBench is a Godot 4.7 C# project with a scene of thousands of moving objects. Their behaviour is sim/boids.gd, an ordinary typed GDScript script: each object steers by its neighbours, which it finds through a uniform grid, bounces off the walls, and moves its Sprite2D every frame. The project uses that file twice:
- GDScript: as a GDScript script, run by Godot’s GDScript VM.
- Typhon: compiled by Typhon’s GDScript front end to C# and built into the project’s C# assembly, where it is an ordinary Godot C# script class.
bench.gd, a GDScript driver that Typhon does not compile, runs both variants and prints how long the update of a frame takes.
How the compiled script gets into Godot
Godot’s C# scripts need glue code that Godot’s own source generators write. Source generators do not see each other’s output, so the project does not use Typhon’s source generator. With TyphonEmitToDisk, a build step before the C# compiler writes the C# for the listed .gd files and Typhon’s runtime into .godot/typhon/, and the C# compiler compiles them with the project’s own files:
<TyphonEmitToDisk>true</TyphonEmitToDisk>
<TyphonEmitDir>$(MSBuildProjectDirectory)/.godot/typhon/</TyphonEmitDir>
<TyphonCompile Include="sim/boids.gd" />
Godot’s generators then treat Boids.cs like a hand-written script. A build with dotnet build produced Boids.cs with #line directives that point to boids.gd, and the assembly carries Godot’s script path res://.godot/typhon/Boids.cs for the class.
Results
The sample’s README reports these times for the simulation step per frame, the best of three runs of 300 frames, measured on an Intel Core i7-10700K with Windows 11, Godot 4.7.2 and .NET 10:
| Objects | GDScript | Typhon | Speed-up | Simulation part | Node updates |
|---|---|---|---|---|---|
| 1,000 | 3.00 ms | 1.20 ms | 2.5x | 5.1x | about the same |
| 4,000 | 19.20 ms | 6.77 ms | 2.8x | 5.4x | about the same |
| 16,000 | 187.02 ms | 52.09 ms | 3.6x | 4.8x | about the same |
The script’s own logic ran about five times faster compiled. Moving the nodes is work of the engine and cost the same in both variants, which is why the whole step gained less, especially with few objects. Both variants printed the same checksum over all positions.
The measurement has limits that the README describes. GDScript ran in the editor binary, which is a debug-enabled build. An exported game runs GDScript in the release template, which is somewhat faster and was not measured. The numbers varied between runs by 10 to 20 %.
Running the sample
godot --headless --path samples/GodotBench --build-solutions --quit
godot --headless --path samples/GodotBench -- --counts=1000,4000,16000 --frames=300 --warmup=100 --repeat=3
The sample needs Godot 4.7 with .NET support and a .NET SDK that builds net10.0. dotnet build samples/GodotBench/GodotBench.csproj builds the assembly without the editor. The sample is not part of Typhon.slnx, because it needs Godot’s SDK.