kpreid / all-is-cubes

Yet another block/voxel game; in this one the blocks are made out of blocks. Runs in browsers on WebGL+WebAssembly.
https://kpreid.dreamwidth.org/tag/all+is+cubes
Apache License 2.0
164 stars 8 forks source link

Review math inlining #493

Closed kpreid closed 4 months ago

kpreid commented 4 months ago

In commit 45a772df73582609cbeb57d69397122bff72db94 I split the math and raycast code into a new library crate, all-is-cubes-base. Unfortunately, I didn’t think at the time about the effect this would have on function inlining. rustc currently has a heuristic for marking small functions inlinable, but it doesn't seem to suffice. After a slapdash addition of #[inline] where it seemed like it would make sense, I get the following notable results in benchmarks:

Bench target Benchmark name Effect of inlining on run time
space space-bulk-mutation/* -0%..-96%
space GridAab/iter_for_each -42%
save load -21%
mesh block/* -10%..-26%
raytrace threaded/* +20%..+29%
mesh space/* +7%..+41%
block evaluate/* +16%..+56%
raycast many steps * +85%

Benchmarks run on my laptop have quite unstable results, but these are huge differences which I am confident are significant. But since they are differences in both directions, we need to break down the #[inline] changes into smaller units to determine what's actually improving performance and what's making it worse.

kpreid commented 4 months ago

The above data was collected by running all benchmarks only once. On re-testing, it seems that a lot of the apparent losses (and gains) may have been noise. Sigh.

kpreid commented 4 months ago

5c90bca42869f764931d53622ce2939f284fd6e1 puts in the rest of the inlining. In the end, I couldn't find any consistent regression.