minetest-mods / ccompass

https://forum.minetest.net/viewtopic.php?f=9&t=17881
Other
5 stars 9 forks source link

Use globalstep instead of minetest.after #23

Closed TurkeyMcMac closed 2 years ago

TurkeyMcMac commented 2 years ago

This is an improvement to my previous pull request. The main advantage of using globalstep is that the cost of ccompass shows up in the profiler. In singleplayer when no one is using a compass, the average cost per step is only about 10 microseconds. One problem with the minetest.after solution is its interaction with other users of minetest.after. Whenever any pending after callback runs, all the others must be checked. This could scale poorly. The globalstep solution is more predictable.

SmallJoker commented 2 years ago

Whenever any pending after callback runs, all the others must be checked.

What do you mean by that? minetest.after went through several optimization steps already. The overhead compared to the globalstep method is pretty much negligible due to low simultaneous job count and efficient queue processing.

TurkeyMcMac commented 2 years ago

The code for minetest.after records time_next when the job list should next be checked. However, it does not record which one should be checked. So when time_next is up, all the pending jobs are checked for expiration.

TurkeyMcMac commented 2 years ago

Probably not worth it.