Skip to content

[core] Split raylet cython file into multiple files (DynamicObjectRefGenerator) #52095

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
92f3a97
refactor: move DynamicObjectRefGenerator to separate file
machichima Apr 8, 2025
8bf561a
Merge branch 'master' of github.com:ray-project/ray into 52029-split-…
machichima Apr 8, 2025
42183d3
fix: update cimport to import
machichima Apr 9, 2025
c9260f0
Merge branch 'master' of github.com:ray-project/ray into 52029-split-…
machichima Apr 12, 2025
4b6e92d
fix: DynamicObjectRefGenerator to py file
machichima Apr 12, 2025
2179700
Merge branch 'master' into 52029-split-cython-dynamic-obj-ref-gen
machichima Apr 12, 2025
02ec294
fix: add api annotation
machichima Apr 12, 2025
7ecc232
style: lint
machichima Apr 12, 2025
cd97ed6
fix: make cython_components into module
machichima Apr 12, 2025
eec23ee
Merge branch 'master' into 52029-split-cython-dynamic-obj-ref-gen
machichima Apr 13, 2025
f0257a5
Merge branch 'master' into 52029-split-cython-dynamic-obj-ref-gen
machichima Apr 13, 2025
9f6f924
Merge branch 'master' into 52029-split-cython-dynamic-obj-ref-gen
machichima Apr 14, 2025
372d513
refactor: move file to _private
machichima Apr 14, 2025
05c3478
Merge branch 'master' of github.com:ray-project/ray into 52029-split-…
machichima Apr 15, 2025
7e6998f
Merge branch 'master' of github.com:ray-project/ray into 52029-split-…
machichima Apr 16, 2025
4a41b68
Merge branch 'master' of github.com:ray-project/ray into 52029-split-…
machichima Apr 17, 2025
d894486
refactor: add type hints
machichima Apr 17, 2025
aa610c4
fix: type checking import ray
machichima Apr 17, 2025
fc27b72
Merge branch 'master' into 52029-split-cython-dynamic-obj-ref-gen
machichima Apr 18, 2025
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
22 changes: 22 additions & 0 deletions python/ray/_private/object_ref_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations
from ray.util.annotations import DeveloperAPI
from typing import Iterator, List, TYPE_CHECKING

if TYPE_CHECKING:
import ray


@DeveloperAPI
class DynamicObjectRefGenerator:
def __init__(self, refs: List["ray.ObjectRef"]):
# TODO(swang): As an optimization, can also store the generator
# ObjectID so that we don't need to keep individual ref counts for the
# inner ObjectRefs.
self._refs: List["ray.ObjectRef"] = refs

def __iter__(self) -> Iterator("ray.ObjectRef"):
for ref in self._refs:
yield ref

def __len__(self) -> int:
return len(self._refs)
17 changes: 1 addition & 16 deletions python/ray/_raylet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ import ray.core.generated.common_pb2 as common_pb2
import ray._private.memory_monitor as memory_monitor
import ray._private.profiling as profiling
from ray._private.utils import decode, DeferSigint
from ray._private.object_ref_generator import DynamicObjectRefGenerator
from ray.util.annotations import PublicAPI

cimport cpython
Expand Down Expand Up @@ -276,22 +277,6 @@ async_task_name = contextvars.ContextVar('async_task_name', default=None)
async_task_function_name = contextvars.ContextVar('async_task_function_name',
default=None)


class DynamicObjectRefGenerator:
def __init__(self, refs):
# TODO(swang): As an optimization, can also store the generator
# ObjectID so that we don't need to keep individual ref counts for the
# inner ObjectRefs.
self._refs = refs

def __iter__(self):
while self._refs:
yield self._refs.pop(0)

def __len__(self):
return len(self._refs)


class ObjectRefGenerator:
"""A generator to obtain object references
from a task in a streaming manner.
Expand Down