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

Optimize get_objects_inside_radius calls #9671

Merged

Conversation

nerzhul
Copy link
Member

@nerzhul nerzhul commented Apr 14, 2020

our previous implementation calls the ActiveObjectMgr to return ids and then lookup those ids in the same map and test each object
Instead now we call the global map to return the pointers directly and we ask filtering when building the list using lamba.

This drop double looping over ranges of active objects (and then filtered one) and drop x lookups on the map regarding the first call results

To do

This PR is a Ready for Review.

How to test

Have item_drops and a mob framework with mobs and just see it works (a little bit better)

@nerzhul nerzhul force-pushed the feature/lightweight_get_object_inside_radius branch 5 times, most recently from 5056d22 to 3230965 Compare April 14, 2020 20:05
src/collision.cpp Show resolved Hide resolved
src/collision.cpp Outdated Show resolved Hide resolved
src/server/activeobjectmgr.cpp Outdated Show resolved Hide resolved
src/serverenvironment.cpp Outdated Show resolved Hide resolved
our previous implementation calls the ActiveObjectMgr to return ids and then lookup those ids in the same map and test each object
Instead now we call the global map to return the pointers directly and we ask filtering when building the list using lamba.

This drop double looping over ranges of active objects (and then filtered one) and drop x lookups on the map regarding the first call results
@nerzhul nerzhul force-pushed the feature/lightweight_get_object_inside_radius branch from 3230965 to ccf46ef Compare April 15, 2020 06:10
@nerzhul nerzhul requested a review from sfan5 April 15, 2020 06:10
@SmallJoker
Copy link
Member

SmallJoker commented Apr 15, 2020

Found fitting test mod (N° 02/65): #6803 (comment)
Addition in collision.cpp L360:

  • ScopeProfiler sp(g_profiler, "Objects in radius", SPT_AVG);

Addition in the linked test mod:

  • minetest.registered_entities["__builtin:item"].initial_properties.collide_with_objects = true

Test command: /a 3

PR + profiler: 82us (8.2e-5)
master + profiler: 142us (0.000142)
Each ~3000 calls/second
Regarding the collision code (only), I measured a ~40% speed improvement.

src/serverenvironment.h Outdated Show resolved Hide resolved
@sfan5 sfan5 changed the title Optimize get_object_inside_radius call Optimize get_objects_inside_radius calls Apr 15, 2020
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works, other than the review comment.

@nerzhul
Copy link
Member Author

nerzhul commented Apr 15, 2020

Found fitting test mod (N° 02/65): #6803 (comment)
Addition in collision.cpp L360:

* `ScopeProfiler sp(g_profiler, "Objects in radius", SPT_AVG);`

Addition in the linked test mod:

* ` minetest.registered_entities["__builtin:item"].initial_properties.collide_with_objects = true`

Test command: /a 3

PR + profiler: 82us (8.2e-5)
master + profiler: 142us (0.000142)
Each ~3000 calls/second
Regarding the collision code (only), I measured a ~40% speed improvement.

thanks for the tests @SmallJoker

@nerzhul nerzhul force-pushed the feature/lightweight_get_object_inside_radius branch from d876167 to 023d407 Compare April 16, 2020 06:24
@nerzhul nerzhul merged commit e8ac5a3 into minetest:master Apr 16, 2020
@nerzhul nerzhul deleted the feature/lightweight_get_object_inside_radius branch April 16, 2020 06:25
aldum pushed a commit to banyamesterseg/minetest that referenced this pull request Apr 16, 2020
* Optimize getObjectsInsideRadius calls

our previous implementation calls the ActiveObjectMgr to return ids and then lookup those ids in the same map and test each object
Instead now we call the global map to return the pointers directly and we ask filtering when building the list using lamba.

This drop double looping over ranges of active objects (and then filtered one) and drop x lookups on the map regarding the first call results
nerzhul added a commit to nerzhul/minetest that referenced this pull request Apr 27, 2020
* Optimize getObjectsInsideRadius calls

our previous implementation calls the ActiveObjectMgr to return ids and then lookup those ids in the same map and test each object
Instead now we call the global map to return the pointers directly and we ask filtering when building the list using lamba.

This drop double looping over ranges of active objects (and then filtered one) and drop x lookups on the map regarding the first call results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants