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

ConfigItem::CommitNewItems(): pre-sort types by their load dependencies once #10003

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

Conversation

Al2Klimov
Copy link
Member

to avoid complicated nested loops, iterating over the same types and
checking dependencies over and over, skipping already completed ones.

@Al2Klimov Al2Klimov added the core/quality Improve code, libraries, algorithms, inline docs label Feb 15, 2024
@cla-bot cla-bot bot added the cla/signed label Feb 15, 2024
Comment on lines 456 to +458
for (const Type::Ptr& type : Type::GetAllTypes()) {
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
types.insert(type);
types.emplace_back(type);
Copy link
Member

@yhabteab yhabteab Feb 15, 2024

Choose a reason for hiding this comment

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

Instead of copying the types around, you can access Type::GetAllTypes() directly within your new method or pass the types without having to copy them if you need the arguments for your unittest. You can then perform this check below when they are actually loaded.

for (const Type::Ptr& type : Type::GetAllTypes()) {
if (ConfigObject::TypeInstance->IsAssignableFrom(type))
types.emplace_back(type);
}

for (auto& type : types) {
pending.emplace(type.get());
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't suggesting you to remove this check, I was just pointing out that you are unnecessarily copying around the types and should avoid doing that. It's not something that already existed and simply saying it will be fixed "one nice day" isn't an argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

But not all types are config types.

Copy link
Member

Choose a reason for hiding this comment

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

But not all types are config types.

Why would that matter to you?

Copy link
Member Author

Choose a reason for hiding this comment

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

CONFIG items get committed here, of course only CONFIG types are relevant here. Btw. that preserved check IS "something that already existed" (just like #10003 (comment)).

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 think you get my point her! My suggestion is to drop this loop entirely and move the check down here instead. Your sort method shouldn't care whether a type is assignable to a config object or not.

ready = true;

for (auto dep : type->GetLoadDependencies()) {
if (loaded.find(dep) == loaded.end()) {
Copy link
Member

Choose a reason for hiding this comment

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

You've omitted a check from the previous version of the code.

types.find(pLoadDep) != types.end() ---

Copy link
Member Author

Choose a reason for hiding this comment

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

Type::SortByLoadDependencies() auto-includes all load dependencies, so this case vanishes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sort functions do not add values, so if it does, the function name is misleading.

Copy link
Member Author

Choose a reason for hiding this comment

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

Re-added it.

…es once

to avoid complicated nested loops, iterating over the same types and
checking dependencies over and over, skipping already completed ones.
@yhabteab yhabteab removed their request for review February 21, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed core/quality Improve code, libraries, algorithms, inline docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants