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

Reduce build time by suppressing template instantiation #1419

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

shouth
Copy link
Contributor

@shouth shouth commented Oct 10, 2024

Description

Abstract

This PR reduces the build time of openscenario_interpreter by suppressing heavy template instantiation.

Background

openscenario_interpreter heavily relies on templated components. These components are typically instantiated and optimized per translation unit, which can lead to longer build times.

Details

Added several explicit instantiations to readAttribute and moved the substitute() function used internally to the cpp file. No changes were made to the algorithm itself.

Added several explicit instantiations to readElement. Additionally, the choice() function was made non-template and its implementation was moved to the cpp file. No changes were made to the algorithm itself. Due to this change, the arguments of the choice() function have changed from "variadic arguments of std::pair" to "std::unordered_map," resulting in a slight modification in how the arguments are described in the places where choice() is called. Most of the changes in the diffs are due to this modification.

Removed the template specialization declarations in DistanceCondition / RelativeDistanceCondition. There are no impacts on other classes due to this change. With the removal of the declarations, the implementation of the distance() function has been moved after the specialization.

References

N/A

Destructive Changes

N/A

Known Limitations

N/A

Copy link

Checklist for reviewers ☑️

All references to "You" in the following text refer to the code reviewer.

  • Is this pull request written in a way that is easy to read from a third-party perspective?
  • Is there sufficient information (background, purpose, specification, algorithm description, list of disruptive changes, and migration guide) in the description of this pull request?
  • If this pull request contains a destructive change, does this pull request contain the migration guide?
  • Labels of this pull request are valid?
  • All unit tests/integration tests are included in this pull request? If you think adding test cases is unnecessary, please describe why and cross out this line.
  • The documentation for this pull request is enough? If you think adding documents for this pull request is unnecessary, please describe why and cross out this line.

@shouth shouth self-assigned this Oct 10, 2024
@shouth shouth added bump patch If this pull request merged, bump patch version of the scenario_simulator_v2 wait for regression test labels Oct 10, 2024
Copy link

sonarcloud bot commented Oct 24, 2024

@shouth shouth marked this pull request as ready for review October 24, 2024 07:00
@yamacir-kit yamacir-kit self-requested a review October 24, 2024 07:02
@@ -54,11 +54,13 @@ ament_export_include_directories(${boost_json_SOURCE_DIR}/include)
file(GLOB ${PROJECT_NAME}_POSIX_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/posix/*.cpp)
file(GLOB ${PROJECT_NAME}_SYNTAX_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/syntax/*.cpp)
file(GLOB ${PROJECT_NAME}_UTILITY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/utility/*.cpp)
file(GLOB ${PROJECT_NAME}_READER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/reader/*.cpp)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please sort in lexicographic order unless there is a technical reason not to.


ament_auto_add_library(${PROJECT_NAME} SHARED
${${PROJECT_NAME}_POSIX_SOURCES}
${${PROJECT_NAME}_SYNTAX_SOURCES}
${${PROJECT_NAME}_UTILITY_SOURCES}
${${PROJECT_NAME}_READER_SOURCES}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please sort in lexicographic order unless there is a technical reason not to.

}
inline namespace reader
{
auto substitute(std::string attribute, const Scope & scope) -> String;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
auto substitute(std::string attribute, const Scope & scope) -> String;
auto substitute(const std::string & attribute, const Scope & scope) -> String;

@@ -177,5 +133,4 @@ auto readAttribute(const std::string & name, const Node & node, const Scope & sc
}
} // namespace reader
} // namespace openscenario_interpreter
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
} // namespace openscenario_interpreter
} // namespace openscenario_interpreter

Comment on lines +101 to +112
extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> Boolean;
extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> UnsignedShort;
extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> UnsignedInteger;
extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> Double;
extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> String;
extern template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> syntax::Rule;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please sort in lexicographic order unless there is a technical reason not to.

@@ -36,6 +36,17 @@

namespace openscenario_interpreter
{

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

Comment on lines +176 to +178
auto choice(
const pugi::xml_node & node,
std::unordered_map<std::string, std::function<Object(const pugi::xml_node &)>> callees) -> Object;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
auto choice(
const pugi::xml_node & node,
std::unordered_map<std::string, std::function<Object(const pugi::xml_node &)>> callees) -> Object;
auto choice(
const pugi::xml_node & node,
const std::unordered_map<std::string, std::function<Object(const pugi::xml_node &)>> & callees) -> Object;

{
inline namespace reader
{
auto substitute(std::string attribute, const Scope & scope) -> String
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
auto substitute(std::string attribute, const Scope & scope) -> String
auto substitute(const std::string & attribute, const Scope & scope) -> String

Comment on lines +89 to +97
template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Boolean;
template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> UnsignedShort;
template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> UnsignedInteger;
template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> Double;
template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &) -> String;
template auto readAttribute(const std::string &, const pugi::xml_node &, const Scope &)
-> syntax::Rule;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please sort in lexicographic order unless there is a technical reason not to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch If this pull request merged, bump patch version of the scenario_simulator_v2 wait for regression test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants