Skip to content

Conversation

mregrock
Copy link
Collaborator

@mregrock mregrock commented Sep 12, 2025

Changelog entry

Some optimizations in ResolveAll

Let:
L - count of labels
I - count of labels with "in" in selectors
N - count of labels with "not in" in selectors
F - average time for Value.Contains() for TSet<TString>

Old Fit gave us: O(L * (logI + logN + F), new Fit will give us O((I + N) * F). (I + N) always less than L (obviously)

Changelog category

  • Not for changelog (changelog entry is not required)

Description for reviewers

...

Copy link

github-actions bot commented Sep 12, 2025

🟢 2025-09-12 15:31:18 UTC The validation of the Pull Request description is successful.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the ResolveAll function by improving the Fit function's performance through pre-compilation of selector data structures. The change reduces time complexity from O(L * (logI + logN + M)) to O((I + N) * M) where L is the total label count, I and N are "in" and "not in" selector counts respectively.

  • Refactored the Fit function to use pre-compiled selector indices instead of map lookups
  • Added hash template specializations for TLabel and TVector types
  • Introduced TCompiledSelector structure to cache selector mappings with label indices

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
ydb/library/yaml_config/public/yaml_config.h Added hash.h include for new hash map functionality
ydb/library/yaml_config/public/yaml_config.cpp Implemented optimization with pre-compiled selectors and updated Fit function signature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

THashMap<TString, int> nameToIndex;
nameToIndex.reserve(labelNames.size());
for (size_t i = 0; i < labelNames.size(); ++i) {
nameToIndex[labelNames[i]] = static_cast<int>(i);
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

Using static_cast for size_t to int conversion could cause overflow for very large indices. Consider using a bounds check or changing the data structure to use size_t consistently.

Copilot uses AI. Check for mistakes.

Comment on lines +410 to +416
for (size_t i = 0; i < notIn.size(); ++i) {
int idx = notIn[i].first;
const auto& label = labels[idx];
if (label.Type != TLabel::EType::Negative && notIn[i].second->Values.contains(label.Value)) {
return false;
}
}
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

The bounds checking for idx against labels.size() is missing. If nameToIndex contains invalid indices, this could lead to out-of-bounds access.

Copilot uses AI. Check for mistakes.

Comment on lines +417 to 426
for (size_t i = 0; i < in.size(); ++i) {
int idx = in[i].first;
const auto& label = labels[idx];
if (label.Type == TLabel::EType::Negative) {
return false;
}
if (!in[i].second->Values.contains(label.Value)) {
return false;
}
}
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

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

The bounds checking for idx against labels.size() is missing. If nameToIndex contains invalid indices, this could lead to out-of-bounds access.

Copilot uses AI. Check for mistakes.

Copy link

github-actions bot commented Sep 12, 2025

2025-09-12 15:31:01 UTC Pre-commit check linux-x86_64-release-asan for 3de0f04 has started.
2025-09-12 15:31:36 UTC Artifacts will be uploaded here
2025-09-12 15:35:52 UTC ya make is running...
🟡 2025-09-12 18:17:07 UTC Some tests failed, follow the links below. This fail is not in blocking policy yet

Test history | Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
17280 16835 0 186 224 35

🟢 2025-09-12 18:18:34 UTC Build successful.
🟢 2025-09-12 18:18:57 UTC ydbd size 4.0 GiB changed* by +21.7 KiB, which is < 100.0 KiB vs main: OK

ydbd size dash main: 9cdcaad merge: 3de0f04 diff diff %
ydbd size 4 321 376 328 Bytes 4 321 398 512 Bytes +21.7 KiB +0.001%
ydbd stripped size 1 494 523 928 Bytes 1 494 528 728 Bytes +4.7 KiB +0.000%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

Copy link

github-actions bot commented Sep 12, 2025

2025-09-12 15:32:10 UTC Pre-commit check linux-x86_64-relwithdebinfo for 3de0f04 has started.
2025-09-12 15:32:39 UTC Artifacts will be uploaded here
2025-09-12 15:36:19 UTC ya make is running...
🟡 2025-09-12 17:44:46 UTC Some tests failed, follow the links below. Going to retry failed tests...

Test history | Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
40087 37316 0 6 2730 35

2025-09-12 17:48:43 UTC ya make is running... (failed tests rerun, try 2)
🟢 2025-09-12 18:04:41 UTC Tests successful.

Test history | Ya make output | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
577 (only retried tests) 553 0 0 1 23

🟢 2025-09-12 18:04:51 UTC Build successful.
🟢 2025-09-12 18:05:08 UTC ydbd size 2.3 GiB changed* by +25.4 KiB, which is < 100.0 KiB vs main: OK

ydbd size dash main: 9cdcaad merge: 3de0f04 diff diff %
ydbd size 2 469 982 928 Bytes 2 470 008 888 Bytes +25.4 KiB +0.001%
ydbd stripped size 516 058 728 Bytes 516 062 120 Bytes +3.3 KiB +0.001%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant