Skip to content

Reduce dynamic allocations for AABB queries#2001

Merged
alecjacobson merged 5 commits intolibigl:mainfrom
svenpilz:reduceDynamicAllocations
Aug 20, 2023
Merged

Reduce dynamic allocations for AABB queries#2001
alecjacobson merged 5 commits intolibigl:mainfrom
svenpilz:reduceDynamicAllocations

Conversation

@svenpilz
Copy link
Copy Markdown
Contributor

@svenpilz svenpilz commented Mar 14, 2022

Regarding discussion #1959.

Reduces dynamic allocations which would reduce performance on Emscripten/WebAssembly builds when multi-threading is enabled. Enabling multi-threading on that platform makes malloc/free atomic.

Checklist

  • All changes meet libigl style-guidelines.
  • Adds new .cpp file.
  • Adds corresponding unit test.
  • This is a minor change.

@svenpilz svenpilz changed the title Reduce dynamic allocations Reduce dynamic allocations for AARB queries Mar 14, 2022
Copy link
Copy Markdown
Contributor

@alecjacobson alecjacobson left a comment

Choose a reason for hiding this comment

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

Thanks! Overall, this is a good change. I left a couple notes, it'd be nice to hear your thoughts on.

typename DerivedV,
typename DerivedF>
IGL_INLINE bool ray_triangle_intersect(
Eigen::Vector3d s_d,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should these be const references rather than non-const pass-by-copy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. I cannot remember why I did it like that. Will fix that.

I was also not sure about your usage of auto and if you like named variables to give some context, even if they are basically just temporaries. Like auto d = v.cast<double>(); foo(d) vs. foo(v.cast<double>()).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I remember now why it took it by copy, intersect_triangle1 needs non-const arguments. But reworked to hide this from the caller and to be consistent with the other functions.

template <
typename DerivedV,
typename DerivedF>
IGL_INLINE bool ray_triangle_intersect(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should document this in the header.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Guess it makes sense to also have the vectors's scalar type as a template parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added to the header.

{
hit = hits.front();
return true;
// Shortcut for AABB based queries.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would it make more sense for the AABB code to call this one directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is a good question. I haven't really looked at the AABB code. Do you think people would use this function here directly, could this be a common use case? If the AABB is the only caller with one triangle, guess adapting there would be the better place.

@alecjacobson alecjacobson changed the title Reduce dynamic allocations for AARB queries Reduce dynamic allocations for AABB queries Mar 14, 2022
@svenpilz
Copy link
Copy Markdown
Contributor Author

Also added a small unit test.

@svenpilz svenpilz requested a review from alecjacobson April 8, 2022 09:49
@alecjacobson
Copy link
Copy Markdown
Contributor

hopefully the builds and tests work and we can merge this

@svenpilz
Copy link
Copy Markdown
Contributor Author

Could not reproduce the failing test on Linux. Tried GCC 10, and clang 13 in Debug with address and undefined sanitizer. @alecjacobson, do you have an idea here?

@alecjacobson alecjacobson merged commit 17787c8 into libigl:main Aug 20, 2023
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.

2 participants