Skip to content

Commit

Permalink
Avoid pull_full_properties() in print_resources_as_table
Browse files Browse the repository at this point in the history
This improves performance in cases where pull_full_properties
contains properties that are expensive to query but are not
needed in the table.

Reduces time to list CPCs from over 20 seconds to under
1 second on my test system.

Signed-off-by: Simon Spinner <sspinner@de.ibm.com>
  • Loading branch information
simon-spinner authored and andy-maier committed Apr 28, 2024
1 parent 9b95495 commit 1b217a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Released: not yet
* The safety run for all dependencies now must succeed when the test workflow
is run for a release (i.e. branch name 'release_...').

* Improved performance of 'list' commands by pulling only the properties
needed for the output, instead of all of them. This reduced the time to list
CPCs from over 20 seconds to under 1 second on a test system.

**Cleanup:**

**Known issues:**
Expand Down
15 changes: 11 additions & 4 deletions zhmccli/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,13 +725,20 @@ def print_resources_as_table(
for resource in resources:
resource_props = {}
if show_list:
props_to_query = []
for name in show_list:
if additions and name in additions:
value = additions[name][resource.uri]
resource_props[name] = additions[name][resource.uri]
prop_names[name] = None
else:
# May raise zhmcclient exceptions
value = resource.prop(name)
resource_props[name] = value
props_to_query.append(name)
# Pull selected properties into cache in one call.
# Resource.prop() calls pull_full_properties if the value is
# not cached which is expensive for certain properties.
resource.pull_properties(props_to_query)
for name in props_to_query:
# May raise zhmcclient exceptions
resource_props[name] = resource.prop(name)
prop_names[name] = None
else:
for name in sorted(resource.properties):
Expand Down

0 comments on commit 1b217a0

Please sign in to comment.