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

TypeTable/TypeInfo optimization #5634

Merged
merged 5 commits into from
Sep 17, 2024
Merged

Conversation

mzient
Copy link
Contributor

@mzient mzient commented Sep 11, 2024

Category:

Refactoring (Redesign of existing code that doesn't affect functionality)
Optimization

Description:

  • TypeInfo uses string_view for type name
  • TypeTable stores types in an array of pointers
  • TypeTable read access is lockless (write access needs a lock)

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: DALI-3967

- TypeInfo uses string_view for type name
- TypeTable stores types in an array
- TypeTable read access is lockless

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18437492]: BUILD STARTED

return nullptr;
return &id_it->second;
return (*types)[idx];
Copy link
Member

Choose a reason for hiding this comment

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

What happens when RegisterType allocated new vector of TypeInfo pointers because of idx >= type_info_map_->size() and we're asking for some type registered earlier? Won't we end up with nullptr 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.

OK, there was as insert that copied the previous vector, but I must have lost it somewhere along the way. This also shows, that this is likely untested. I'll add tests that cover adding new types.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18437886]: BUILD STARTED

Comment on lines 496 to 500
TypeInfoMap *type_info_map_ = nullptr;

spinlock lock_;
std::unordered_map<std::type_index, DALIDataType> type_map_;
// Unordered maps do not work with enums,
// so we need to use underlying type instead of DALIDataType
std::unordered_map<std::underlying_type_t<DALIDataType>, TypeInfo> type_info_map_;
int index_ = DALI_DATATYPE_END;
std::mutex insert_lock_;
std::list<TypeInfoMap> type_info_maps_;
std::list<TypeInfo> type_infos_;
Copy link
Member

Choose a reason for hiding this comment

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

Can you document the purpose of those members? Especially why not just a single vector (to avoid locking on read, right?).

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18437492]: BUILD FAILED

Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18439899]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18439899]: BUILD FAILED

Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18465196]: BUILD STARTED

Comment on lines 100 to 111
IMPL_HAS_MEMBER(value);

template <typename T, decltype(type2id<T>::value) = {}>
void CheckBuiltinType(const TypeInfo *t) {
EXPECT_EQ(t->id(), type2id<T>::value);
EXPECT_EQ(TypeTable::GetTypeId<T>(), type2id<T>::value);
}

template <typename T>
void CheckBuiltinType(...) {}


Copy link
Contributor Author

Choose a reason for hiding this comment

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

This passes in a single-DLL scenario, but it's a valid test anyway, so let's keep it.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18465196]: BUILD FAILED

Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18466402]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [18466402]: BUILD PASSED

@mzient mzient merged commit 8904209 into NVIDIA:main Sep 17, 2024
6 checks passed
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.

4 participants