Skip to content

Conversation

schnellerhase
Copy link
Contributor

Addresses undesired changes introduced in #3722. And reactivates the clang tidy check temporary deactivated in #3814.

  • All occurrences of const std::shared_ptr<>& are now removed. performance-unnecessary-value-param-check either expects pass by const ref or by value together with move semantics. The later is used throughout, consistent with previous use.
  • Introduces custom special case handling for nanobind::ndarray to allow for it to be passed (as non-trivially copyable type) by value and not by const &.
  • The same special case treatment could be applied to the std::string and std::filesystem::path arguments. However this would also disallow the checks in other critical parts of the code and it is preferable to stay consistent. Therefore this returns to the initial changes for those in the python exports. If not desired, we could also use another clang-tidy config file for the python exports to only disregard in this section.
  • Deactivates by hand clang-tidy check for small array which should be passed by value. This could be used for any such cases that might arise in the future.

Copy link
Member

@garth-wells garth-wells left a comment

Choose a reason for hiding this comment

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

I think most of these clang-tidy changes add complexity, are misleading, have no effect, or have no meaningful effect.

I don't mind having a clang-tidy action with workflow_dispatch that can advise and be manually reviewed, but developer judgement should be used for changes.

If we have an action for clang-tidy, it should report red only if it fails to run rather than when clang-tidy suggests changes.

std::span(parent_cell.data(), parent_cell.size()));
return dolfinx::mesh::MeshTags<std::int32_t>(
topology1, tdim, std::move(entities), std::move(values));
std::move(topology1), tdim, std::move(entities), std::move(values));
Copy link
Member

Choose a reason for hiding this comment

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

std::move on topology1 is unnecessary and will have no effect since MeshTags takes the shared pointer by value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Meshtags argument (taken by value) is then move constructed, not copy constructed. https://godbolt.org/z/zKb3h46qj

{{{0, 0}, {0, 0}},
std::make_shared<graph::AdjacencyList<std::int32_t>>(
vertex_map->size_local() + vertex_map->num_ghosts())});
_index_maps.insert(
Copy link
Member

Choose a reason for hiding this comment

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

This change adds complexity for no meaningful performance benefit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initialiser lists are not movable. This removes a somewhat hidden copy of vertex_map.


template <typename T>
void declare_function_space(nb::module_& m, std::string type)
void declare_function_space(nb::module_& m, const std::string& type)
Copy link
Member

Choose a reason for hiding this comment

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

Passing strings by reference isn't really needed in cases like this because (i) the code here is isn't performance critical and (ii) the strings are usually short and compilers have 'short string optimisation'.

I prefer to let the developer make the decision because they know the context.

g, std::vector(dofs.data(), dofs.data() + dofs.size()), V);
std::move(g),
std::vector(dofs.data(), dofs.data() + dofs.size()),
std::move(V));
Copy link
Member

Choose a reason for hiding this comment

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

std::move on V not required and will have no effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving std::shared_ptr removes the implied overhead by the atomic reference count increase and decrease associated with copying (and deleting) a std::shared_ptr - moving requires no reference count update.

Copy link
Member

Choose a reason for hiding this comment

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

std::move makes V an rvalue, but the DirichletBC constructor doesn't accept rvalues for the FunctionSpace argument (it takes it by value), which is why it may have no effect unless the compiler can do some copy elision.

Even if it did move the shared pointer, the cost of copying a shared pointer outside a hot loop is trivial. We shouldn't be making code syntactically more complex if there is no measurable performance benefit. Happy to reconsider if a realistic test can demonstrate a meaningful performance difference.

std::vector(V_g_dofs[1].data(),
V_g_dofs[1].data() + V_g_dofs[1].size())};
new (bc) dolfinx::fem::DirichletBC(g, std::move(dofs), V);
new (bc) dolfinx::fem::DirichletBC(std::move(g), std::move(dofs),
Copy link
Member

Choose a reason for hiding this comment

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

No need to move g.

new (fp) dolfinx::fem::Form<T, U>(
spaces, std::move(_integrals), mesh, coefficients, constants,
needs_permutation_data, ptr_to_ref_wrapper_vec(entity_maps));
spaces, std::move(_integrals), std::move(mesh), coefficients,
Copy link
Member

Choose a reason for hiding this comment

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

std::move on mesh not needed.

@schnellerhase schnellerhase force-pushed the schnellerhase/clang-tidy-2.0 branch from 3c871bd to 5f35e79 Compare July 29, 2025 20:23
@schnellerhase
Copy link
Contributor Author

schnellerhase commented Jul 29, 2025

Reverted the changes and changed over to warnings no longer being treated as errors, and running nightly to test clang-tidy works.

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