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

Use shared error type map #214

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dorezyuk
Copy link
Contributor

@dorezyuk dorezyuk commented Oct 28, 2024

Currently the error type map is copy constructed and then placed into a shared pointer which results in the error map not being really shared between the different classes. This Pr fixes it.

@@ -14,13 +15,12 @@ namespace Everest {
namespace error {

struct ErrorDatabase;
struct ErrorTypeMap;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really get what the idea behind all the forward defines was - I've removed it to just use the ErrorTypeMapPtr type

Copy link
Contributor

Choose a reason for hiding this comment

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

The idea of forward declarations is to avoid including dependencies in the header file to reduce compile times after changing something in the included files

Signed-off-by: Dima Dorezyuk <ddo@qwello.eu>
@dorezyuk dorezyuk force-pushed the feat/use_shared_error_map branch from 382a3ca to 1dd7579 Compare October 28, 2024 06:24
@dorezyuk dorezyuk changed the title Use shared error map Use shared error type map Oct 28, 2024
Signed-off-by: Dima Dorezyuk <ddo@qwello.eu>
@dorezyuk dorezyuk force-pushed the feat/use_shared_error_map branch from 4f4d37a to a8d57b5 Compare October 28, 2024 06:34
@andistorm andistorm self-assigned this Oct 29, 2024
@hikinggrass hikinggrass requested a review from andistorm January 3, 2025 10:54
Copy link
Contributor

@andistorm andistorm left a comment

Choose a reason for hiding this comment

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

Thanks for your work here @dorezyuk,

I really would like to merge the optimization of sharing the pointer instead of copying the ErrorTypeMap.
Could you please move the style changes in another PR/Discussion?
Regarding the forward declarations I see a disadvantage in removing them since they can safe compile time by reducing dependencies between the header files.

Please let me know if you have further questions to my comments

Comment on lines +56 to +59
/// Const pointer to a ErrorTypeMap. This is the default how we share the
/// error type map between different classes.
using ConstPtr = std::shared_ptr<const ErrorTypeMap>;

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to keep using std::shared_ptr<const ErrorTypeMap> since it fits the style arround here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if i understand - we're using it

@@ -5,6 +5,9 @@
#define UTILS_ERROR_TYPE_MAP_HPP

#include <filesystem>
#include <map>
#include <memory>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include <memory>

This dependency can be avoided, when not defining this ConstPtr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also not sure if I understand - we use it in this library a lot. What do you mean with "avoid" the dependency? Are you concerned about the preprocessor adding this?


namespace Everest {
namespace error {

struct ErrorTypeMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to keep this forward declaration to avoid unnecessary dependencies in all these header files

@@ -14,13 +15,12 @@ namespace Everest {
namespace error {

struct ErrorDatabase;
struct ErrorTypeMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea of forward declarations is to avoid including dependencies in the header file to reduce compile times after changing something in the included files

@@ -397,7 +397,7 @@ std::tuple<json, int> Config::load_and_validate_with_schema(const fs::path& file
Config::Config(std::shared_ptr<RuntimeSettings> rs) : Config(rs, false) {
}

Config::Config(std::shared_ptr<RuntimeSettings> rs, bool manager) : rs(rs), manager(manager) {
Config::Config(std::shared_ptr<RuntimeSettings> rs, bool manager) : rs(rs), manager(manager), error_map{nullptr} {
Copy link
Contributor

Choose a reason for hiding this comment

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

This default value is not needed, especially because it is initialized in the body of the constructor

Comment on lines +105 to +107
this->impl_error_managers[impl] =
std::make_shared<error::ErrorManagerImpl>(this->config.get_error_map(), error_database, allowed_error_types,
publish_raised_error, publish_cleared_error);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really get what changed here

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