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

flux-resource: improve performance of flux resource list #5823

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
flux-resource: improve performance of ResourceSetExtra initializer
Problem: The ResourceSetExtra class is supposed to be just a wrapper
around a ResourceSet class that adds the convenience `propertiesx`
and `queue` properties. However, using this class is slow because
it reinvokes the underlying ResourceSet initializer, which ends up
creating a unnecessary copy of the resource set from scratch.

Make the class a wrapper by just stashing the original ResourceSet
object and forwarding unknown getattrs to the wrapped object. This
avoids the wasted time recreating the coped resource set.
  • Loading branch information
grondo committed Mar 24, 2024
commit c403aafacc84dfddd61f6dc9f000dd99fadc9508
7 changes: 5 additions & 2 deletions src/cmd/flux-resource.py
Original file line number Diff line number Diff line change
@@ -418,11 +418,14 @@ class ResourceSetExtra(ResourceSet):
def __init__(self, arg=None, version=1, flux_config=None):
self.flux_config = flux_config
if isinstance(arg, ResourceSet):
super().__init__(arg.encode(), version)
self._rset = arg
if arg.state:
self.state = arg.state
else:
super().__init__(arg, version)
self._rset = ResourceSet(arg, version)

def __getattr__(self, attr):
return getattr(self._rset, attr)

@property
def propertiesx(self):