afonsolage / projekto

Voxel game made with Bevy Engine
MIT License
59 stars 4 forks source link

Genesis parallelism #58

Closed afonsolage closed 2 years ago

afonsolage commented 2 years ago

Currently chunk loading, generation, updating and saving are all done in sequence. This PR aims to using Bevy AsyncComputeTaskPool and IoComputeTaskPool to reduce genesis time by increasing parallelism.

afonsolage commented 2 years ago

It seems to have a regression

Before: 35s After: 44s

afonsolage commented 2 years ago
2022-08-24T11:22:43.810508Z TRACE projekto_shaping::light_propagator: Propagating natural light on new 169 chunks
2022-08-24T11:22:59.332578Z TRACE projekto_shaping::light_propagator: Preparing to propagate natural light to neighbors of 169 chunks
2022-08-24T11:22:59.658166Z TRACE projekto_shaping::light_propagator: Propagating light on 169 chunk neighbors
2022-08-24T11:23:05.073777Z TRACE main::world::terraformation::genesis::task: Generation completed! 169 chunks dirty.
2022-08-24T11:23:05.633527Z TRACE projekto_shaping::light_propagator: Preparing to propagate natural light to neighbors of 169 chunks
2022-08-24T11:23:05.958320Z TRACE projekto_shaping::light_propagator: Propagating light on 169 chunk neighbors
2022-08-24T11:23:10.448411Z TRACE projekto_shaping::light_propagator: Preparing to propagate natural light to neighbors of 169 chunks
2022-08-24T11:23:10.778483Z TRACE projekto_shaping::light_propagator: Propagating light on 169 chunk neighbors

The propagation function is doing more work than it should.

afonsolage commented 2 years ago

Loading reduced from 5s, to 2.5s;

Full generation had no reduction since I was unable to parallel compute light, since it would need more rework, which I'll do in another PR.

afonsolage commented 2 years ago

I figured out a way to propagate natural light on new chunks in parallel. Full genesis went from 35s to 26s.

I'm happy with how it is now. I'll cleanup and merge