Borrow function arguments and use one byte type

オープン
#1,987 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
api

調査の方向性

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>.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
4.8k
フォーク
222
平均マージ
1日 16時間
マージ済み PR(30日)
60

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hyperlight-dev/hyperlight のほかの issue

hyperlight-dev/hyperlight の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。