Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized explosion entity exposure calculations #507

Closed

Conversation

RacoonDog
Copy link
Contributor

@RacoonDog RacoonDog commented Mar 16, 2024

Overview

This pull request comprises three optimizations:

  • Optimize exposure raycasts by removing fluid handling, getting hit face, and other useless computations.
  • Short-circuit exposure calculations on discarded entities.
  • Remove duplicate Explosion#getExposure calls.

Since these optimizations specifically target entity-related explosion calculations, they have virtually no effect on single explosions. Chained explosions, however, see massive benefits due to the creation of dropped items & exp orbs which are then affected by the subsequent explosions.

I'm not particularly good at documentation, so suggestions are welcome.

Benchmarks

~150% improvement in time spent exploding 4096 tnts.
Benchmarked using seed -3199243952349285632 (randomly chosen) and 4096 tnt (/fill ~1 ~-7 ~ ~16 ~8 ~15 tnt)

Before:
9492 ms spent in World.createExplosion() Spark profile
before

After:
3832 ms spent in World.createExplosion() Spark profile
after

@virophagesp
Copy link

i tested this, it works well

@2No2Name
Copy link
Member

2No2Name commented May 1, 2024

Seems reasonable, will try to merge it soon

@virophagesp
Copy link

any updates?

@2No2Name
Copy link
Member

2No2Name commented May 11, 2024

I found some issues with the PR, but I am fixing them myself. No need to take action. In case you are curious:

  1. Use of static fields in fast_exposure.ExplosionMixin. (This would lead to issues with switching worlds, multithreading mods, or just having two explosions in the nether and the overworld at the same coordinates)
  2. Sending the wrong velocity to dead players in fast_exposure.ExplosionMixin
  3. Crashing when explosion is outside the world height
  4. Inspiring me to move the optimization to all raycasts, not just explosions

@2No2Name
Copy link
Member

Rebased and included fixes / my own changes.

Thank you very much for your contribution @RacoonDog

@2No2Name 2No2Name closed this May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants