Skip to content

Commit

Permalink
Actually optimise explosions
Browse files Browse the repository at this point in the history
The vast majority of blocks an explosion of power ~4 tries
to destroy are duplicates. The core of the block destroying
part of this patch is to cache the block state, resistance, and
whether it should explode - as those will not change.

The other part of this patch is to optimise the visibility
percentage calculation. The new visibility calculation takes
advantage of the block caching already done by the explosion logic.
It continues to update the cache as the visibility calculation
uses many rays which can overlap significantly.

Effectively, the patch uses a lot of caching to eliminate
redundant operations.

Performance benchmarking explosions is challenging, as it varies
depending on the power, the number of nearby entities, and the
nearby terrain. This means that no benchmark can cover all the cases.
I decided to test a giant block of TNT, as that's where the optimisations
would be needed the most.

I tested using a 50x10x50 block of TNT above ground
and determined the following:

Vanilla time per explosion: 2.27ms
Lithium time per explosion: 1.07ms
This patch time per explosion: 0.45ms

The results indicate that this logic is 5 times faster than Vanilla
and 2.3 times faster than Lithium.
  • Loading branch information
Spottedleaf committed Sep 12, 2023
1 parent c6950e2 commit 3b16d8f
Showing 1 changed file with 469 additions and 0 deletions.
Loading

0 comments on commit 3b16d8f

Please sign in to comment.