Skip to content

Commit f3e0fc7

Browse files
pzhan9facebook-github-bot
authored andcommitted
Change PythonMessage's signature (#402)
Summary: Pull Request resolved: #402 `&[u8]` is much faster than `Vec<u8>` for some reason (See V1 of this diff for comparision). *probably* because: `Vec<u8>` is mapped to pyo3's `PySequence`, and then it does this under the hood: https://fburl.com/code/6cw3osxf `&[u8]` is just a pointer to rust, then rust does `memcpy` under the hood, which is much faster. Reviewed By: moonli, shayne-fletcher Differential Revision: D77594166 fbshipit-source-id: f296c32ae0539e59391f142b8fb4b236f0dfedc7
1 parent 5cde139 commit f3e0fc7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

monarch_hyperactor/src/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl PythonMessage {
208208
#[pyo3(signature = (method, message, response_port, rank))]
209209
fn new(
210210
method: String,
211-
message: Vec<u8>,
211+
message: &[u8],
212212
response_port: Option<EitherPortRef>,
213213
rank: Option<usize>,
214214
) -> Self {

python/tests/_monarch/test_actor.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# pyre-strict
8+
9+
import time
10+
11+
from monarch._rust_bindings.monarch_hyperactor.actor import PythonMessage
12+
13+
14+
def test_python_message() -> None:
15+
"""
16+
Verifies that PythonMessage can be constructed reasonably fast.
17+
"""
18+
method: str = "test_method"
19+
payload: str = "a" * 2**30 # 1gb
20+
blob: bytes = payload.encode("utf-8")
21+
t = time.time()
22+
PythonMessage(method, blob, None, None)
23+
t_spent = time.time() - t
24+
assert t_spent < 1

0 commit comments

Comments
 (0)