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

optimize key librlist functions to improve flux resource list performance #5824

Merged
merged 3 commits into from Mar 25, 2024

Conversation

grondo
Copy link
Contributor

@grondo grondo commented Mar 24, 2024

This PR fixes some key hotspots in librlist and libidset found while profiling poor flux resource list performance.

This is based on #5823 just to show the cumulative performance gains.

On #5823:

$ time src/cmd/flux resource list --from-stdin < ../../large-list.json >/dev/null

real	0m1.790s
user	0m1.662s
sys	0m0.102s

On this PR branch:

$ time src/cmd/flux resource list --from-stdin < ../../large-list.json >/dev/null

real	0m0.826s
user	0m0.715s
sys	0m0.100s

Copy link

codecov bot commented Mar 24, 2024

Codecov Report

Merging #5824 (6903be8) into master (a1070a3) will increase coverage by 0.02%.
The diff coverage is 95.12%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5824      +/-   ##
==========================================
+ Coverage   83.35%   83.37%   +0.02%     
==========================================
  Files         509      509              
  Lines       82494    82528      +34     
==========================================
+ Hits        68759    68805      +46     
+ Misses      13735    13723      -12     
Files Coverage Δ
src/cmd/flux-resource.py 95.44% <100.00%> (+0.27%) ⬆️
src/common/libidset/idset.c 94.27% <100.00%> (-1.32%) ⬇️
src/common/librlist/rnode.c 85.29% <84.61%> (-0.09%) ⬇️

... and 16 files with indirect coverage changes

@garlick
Copy link
Member

garlick commented Mar 24, 2024

Wow great!

Copy link
Member

@garlick garlick left a comment

Choose a reason for hiding this comment

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

LGTM!

@grondo
Copy link
Contributor Author

grondo commented Mar 24, 2024

Thanks! Setting MWP

Problem: Profiling shows that an inordinate amount of time is spent
in util_idset_add_check() when building an rlist object from an
R object. This appears to be beacuse both the idset calls in this
function; idset_has_intersection() and idset_union(); always traverse
all of the idset `b` entries. In the case of building a new rlist,
the idset `a` is empty because we are adding new ids to a new rnode,
so this traversal is completely unnecessary.

In the case that idset `a` is empty, return a copy of `b` and skip
calling the other idset calls completely.
Problem: idset_equal() has to iterate all ids in both idsets being
compared when the idsets are equal. This is twice the necessary work
when the idsets have already been verified to have equal counts.

If the counts of the two idsets have already been verified to be
equivalent, then iterating the second idset is wasted work. Check
for this condition after iterating idset1 and return true immediately.
Problem: Profiling shows the majority of time in rnode_diff() is
spent in idset_subtract() because idset_clear() appears to be quite
an expensive operation.

In the case that two rnodes children are equal, skip idset_subtract()
and simply make the target rnode child empty using a new
rnode_child_clear() function. Since idset_clear() is expensive,
recreate the child idsets instead of trying to clear all ids.
@mergify mergify bot merged commit d115427 into flux-framework:master Mar 25, 2024
33 checks passed
@grondo grondo deleted the rlist-optimize branch March 25, 2024 02:22
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.

None yet

2 participants