-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} using threads to build command table for performance #32518
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
Open
DanielMicrosoft
wants to merge
18
commits into
Azure:dev
Choose a base branch
from
DanielMicrosoft:35856522-improve-command-index-perf
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+179
−46
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a13d2fb
wip: using threads to build command table
DanielMicrosoft 8c25f0e
refactor: export to smaller methods
DanielMicrosoft a53f78a
refactor: refactor smaller methods and add timeout for deadlocks
DanielMicrosoft f320960
refactor: use constants for magic numbers
DanielMicrosoft a4f2398
refactor: remove comments
DanielMicrosoft 430117c
test: add test for command table integrity
DanielMicrosoft ed7147c
refactor: remove comments
DanielMicrosoft 3f51c59
refactor: restore launch.json
DanielMicrosoft b7ccbed
refactor: linting issues
DanielMicrosoft a472ded
refactor: flake issues
DanielMicrosoft 82c2cb5
refactor: flake issues
DanielMicrosoft 89a8e32
refactor: fix lint issue (imports)
DanielMicrosoft 6580aa5
refactor: concurrent.futures Timeout import
DanielMicrosoft f6e769b
Merge branch 'dev' of https://github.com/Azure/azure-cli into 3585652…
DanielMicrosoft 0f57d7a
fix: address co-pilot suggestions
DanielMicrosoft 25d5d6a
fix: address lint error
DanielMicrosoft d02b59f
feature: address threading race conditions concerns
DanielMicrosoft 4f890c8
fix: fix test mocks to return correct params
DanielMicrosoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/azure-cli-core/azure/cli/core/tests/test_command_table_integrity.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import unittest | ||
|
|
||
| from azure.cli.core.mock import DummyCli | ||
| from azure.cli.core import MainCommandsLoader | ||
|
|
||
|
|
||
| class CommandTableIntegrityTest(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.cli_ctx = DummyCli() | ||
|
|
||
| def test_command_table_integrity(self): | ||
| """Test command table loading produces valid, complete results.""" | ||
|
|
||
| # Load command table using current implementation | ||
| loader = MainCommandsLoader(self.cli_ctx) | ||
| loader.load_command_table([]) | ||
|
|
||
| # Test invariants that should always hold: | ||
|
|
||
| # 1. No corruption/duplicates | ||
| command_names = list(loader.command_table.keys()) | ||
| unique_command_names = set(command_names) | ||
| self.assertEqual(len(unique_command_names), len(command_names), "No duplicate commands") | ||
|
|
||
| # 2. Core functionality exists (high-level groups that should always exist) | ||
| core_groups = ['vm', 'network', 'resource', 'account', 'group'] | ||
| existing_groups = {cmd.split()[0] for cmd in loader.command_table.keys() if ' ' in cmd} | ||
| missing_core = [group for group in core_groups if group not in existing_groups] | ||
| self.assertEqual(len(missing_core), 0, f"Missing core command groups: {missing_core}") | ||
|
|
||
| # 3. Structural integrity | ||
| commands_without_source = [] | ||
| for cmd_name, cmd_obj in loader.command_table.items(): | ||
| if not hasattr(cmd_obj, 'command_source') or not cmd_obj.command_source: | ||
| commands_without_source.append(cmd_name) | ||
|
|
||
| self.assertEqual(len(commands_without_source), 0, | ||
| f"Commands missing source: {commands_without_source[:5]}...") | ||
|
|
||
| # 4. Basic sanity - we loaded SOMETHING | ||
| self.assertGreater(len(loader.command_table), 0, "Commands were loaded") | ||
| self.assertGreater(len(loader.command_group_table), 0, "Groups were loaded") | ||
|
|
||
| # 5. Verify core groups are properly represented | ||
| found_core_groups = sorted(existing_groups & set(core_groups)) | ||
| self.assertGreaterEqual(len(found_core_groups), 3, | ||
| f"At least 3 core command groups should be present, found: {found_core_groups}") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a command only needs to load one module, does creating a
ThreadPoolExecutorand usingexecutor.submitadd more overhead compared to running it directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question. Although it only adds around ~10-50 microseconds.