Borrow function arguments and use one byte type

Aberta
#1,987 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
38/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
rust
Domínio
api

Direção de pesquisa

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

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Rust
Estrelas
4.8k
Forks
222
Merge médio
1d 16h
PRs com merge (30d)
60

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de hyperlight-dev/hyperlight

Todas as issues de hyperlight-dev/hyperlight

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.