Skip to content

Conversation

@dorezyuk
Copy link
Collaborator

@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.

namespace error {

struct ErrorDatabase;
struct ErrorTypeMap;
Copy link
Collaborator 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
Member

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 <[email protected]>
@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 <[email protected]>
@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
Member

@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
Member

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
Collaborator 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


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

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
Collaborator 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
Member

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

namespace error {

struct ErrorDatabase;
struct ErrorTypeMap;
Copy link
Member

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

}

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
Member

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
Member

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

@andistorm andistorm self-requested a review January 27, 2025 07:04
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