Skip to content

[core] Avoid resize in GetAndPinArgsForExecutor#51543

Merged
edoakes merged 3 commits intoray-project:masterfrom
dayshah:pinarg-exec-resize
Mar 25, 2025
Merged

[core] Avoid resize in GetAndPinArgsForExecutor#51543
edoakes merged 3 commits intoray-project:masterfrom
dayshah:pinarg-exec-resize

Conversation

@dayshah
Copy link
Contributor

@dayshah dayshah commented Mar 20, 2025

Why are these changes needed?

Resize is pretty inefficient default constructing all these in the case of a lot of args.

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

dayshah added 2 commits March 19, 2025 17:52
Signed-off-by: dayshah <dhyey2019@gmail.com>
Signed-off-by: dayshah <dhyey2019@gmail.com>
@dayshah dayshah marked this pull request as draft March 22, 2025 23:39
Signed-off-by: dayshah <dhyey2019@gmail.com>
@dayshah dayshah added the go add ONLY when ready to merge, run all tests label Mar 23, 2025
@dayshah dayshah marked this pull request as ready for review March 24, 2025 07:06
@dayshah dayshah requested a review from edoakes March 24, 2025 22:21
arg_refs->at(i) = arg_ref;
by_ref_indices[arg_id].push_back(i);
arg_refs->push_back(arg_ref);
args->emplace_back();
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why do we emplace here?
So in the old impl, args[i] is assigned once via

args->at(i) = std::make_shared<RayObject>(data, metadata, task.ArgInlinedRefs(i), copy_data);

in the new impl, it's emplaced twice

args->emplace_back(); // first time
args->push_back(std::make_shared<RayObject>(std::move(data), std::move(metadata), task.ArgInlinedRefs(i), copy_data));  // second time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's actually if else, so only once like

if something:
    args->emplace_back(); // first time
else:
    args->push_back(std::make_shared<RayObject>(std::move(data), std::move(metadata), task.ArgInlinedRefs(i), copy_data));  // second time

before since we did resize before we'd have the empty shared ptr there anyways in the if case

Copy link
Contributor

Choose a reason for hiding this comment

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

oh icic, sorry for the misread.

Copy link
Contributor

Choose a reason for hiding this comment

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

btw is it possible to early exit?
https://clang.llvm.org/extra/clang-tidy/checks/readability/else-after-return.html
it's actually a good place to use, the if-else block is so big

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya it is possible here but i'd rather not for this because we can save the git blame here and it doesn't really add much to readability in this case

Copy link
Contributor

@dentiny dentiny left a comment

Choose a reason for hiding this comment

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

Nice!

@edoakes edoakes merged commit b391072 into ray-project:master Mar 25, 2025
6 checks passed
@dayshah dayshah deleted the pinarg-exec-resize branch March 25, 2025 19:07
angelinalg pushed a commit to angelinalg/ray that referenced this pull request Mar 26, 2025
Resize is pretty inefficient default constructing all these in the case
of a lot of args.

---------

Signed-off-by: dayshah <dhyey2019@gmail.com>
dhakshin32 pushed a commit to dhakshin32/ray that referenced this pull request Mar 27, 2025
Resize is pretty inefficient default constructing all these in the case
of a lot of args.

---------

Signed-off-by: dayshah <dhyey2019@gmail.com>
Signed-off-by: Dhakshin Suriakannu <d_suriakannu@apple.com>
srinathk10 pushed a commit that referenced this pull request Mar 28, 2025
Resize is pretty inefficient default constructing all these in the case
of a lot of args.

---------

Signed-off-by: dayshah <dhyey2019@gmail.com>
Signed-off-by: Srinath Krishnamachari <srinath.krishnamachari@anyscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-backlog go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments