Skip to content

Commit e2f478a

Browse files
authored
perf(array): use less memory for apply (docarray#312)
1 parent 3c9883e commit e2f478a

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

docarray/array/mixins/parallel.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,8 @@ def apply(self: 'T', *args, **kwargs) -> 'T':
6060
# noqa: DAR201
6161
:return: a new :class:`DocumentArray`
6262
"""
63-
from ... import DocumentArray
64-
65-
new_da = DocumentArray(self.map(*args, **kwargs))
66-
self.clear()
67-
self.extend(new_da)
63+
for doc in self.map(*args, **kwargs):
64+
self[doc.id] = doc
6865
return self
6966

7067
def map(
@@ -157,13 +154,8 @@ def apply_batch(self: 'T', *args, **kwargs) -> 'T':
157154
# noqa: DAR201
158155
:return: a new :class:`DocumentArray`
159156
"""
160-
from ... import DocumentArray
161-
162-
new_da = DocumentArray()
163157
for _b in self.map_batch(*args, **kwargs):
164-
new_da.extend(_b)
165-
self.clear()
166-
self.extend(new_da)
158+
self[[doc.id for doc in _b]] = _b
167159
return self
168160

169161
def map_batch(

0 commit comments

Comments
 (0)