Borrow function arguments and use one byte type

Đang mở
#1,987 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
38/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
api

Hướng nghiên cứu

Start from Sandbox::call on the host side and the guest call_host path, then trace how String, Vec<u8> and Vec<Bytes> arguments are converted and placed into virtqueue buffers. The issue names the target types and copy counts but not files or tests, so locate the serialization and guest parameter-reading code before changing signatures. Done means &str and &[u8] are accepted alongside owned values, and all byte arguments use one wire format whose guest-side read depends on whether the parameter is Vec<u8> or Vec<Bytes>.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A-api S-needs-triage

Function calls copy byte and string arguments more often than they need to.

Problem

  • call and call_host take arguments by value. A caller that holds a &str or &[u8] must clone it first, even though the call only reads it.
  • A function can receive bytes as Vec<u8> or Vec<Bytes>. In the guest, Vec<u8> joins the transport buffers into a new vector and Vec<Bytes> does not. The cost is hidden in the receiver's signature.

Proposal

Callers pass borrowed values. Functions take and return bytes only as Vec<Bytes>.

Arguments Parameters and return types
Scalars i32, u32, i64, u64, f32, f64, bool same, plus () as a return type
Strings &str String
Bytes &[u8], &[u8; N], &[Bytes] Vec<Bytes>

Arguments are what callers pass to call, call_host and #[host_function] stubs. Parameters and return types are what #[guest_function] and host functions declare.

Breaking changes

  • Owned String, Vec<u8>, Bytes and Vec<Bytes> are no longer accepted as arguments. Pass s.as_str(), &v or &chunks.
  • Vec<u8> is no longer a parameter or return type. Use Vec<Bytes>. concat() joins the chunks when a function needs one contiguous buffer.

These are hard breaks, but each fix is a one-line change at a call site or a function signature, and the compile error names it.

Effect

Copies per byte argument, host to guest:

Caller holds Guest parameter (today) Today After
Vec<u8> Vec<u8> 2 1
&[u8] Vec<u8> 3 1
&[u8] Vec<Bytes> 2 1
Vec<Bytes> Vec<Bytes> 1 1

After the change, every byte argument takes one copy: the host writes it into the guest's transport buffers, and the guest reads it from them in place. Guest-to-host calls save the caller's clone. The host still copies guest data once before reading it, for safety.

Ngôn ngữ chính
Rust
Star
4.8k
Fork
222
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
60

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của hyperlight-dev/hyperlight

Tất cả issue của hyperlight-dev/hyperlight

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.