rivet-dev / rivet-dev/dynamic-apps

perf(sidecar): raw-binary readFileSync transfer (skip base64)

Open
#81 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1k
Forks
51
Avg merge
6m
Merged PRs (30d)
13

Description

Background

Guest binary fs.readFileSync(path) (no encoding) goes
_fs.readFileBinary_fsReadFileBinary → mapped to fs.readFileSync with the
binary flag (crates/execution/src/v8_runtime.rs:183) → host returns the bytes as
a base64-encoded JSON object (javascript_sync_rpc_bytes_value:
{ "__agentOsType": "bytes", "base64": "..." }), and the guest decodes with
Buffer.from(base64, "base64") (crates/execution/assets/v8-bridge.source.js).

So every binary file read pays base64 encode (host) + decode (guest) plus ~33%
payload inflation. The base64 round-trip is wasted work.

Proposal

Transfer file bytes as raw binary instead of base64. The bridge response
protocol already has a raw-binary path (status = 2 / Uint8Array, see
crates/v8-runtime/src/host_call.rs). Route readFileSync's binary result through
that path and have the guest do Buffer.from(uint8array) directly.

Why it wasn't done in PR #77

The sync-RPC return type is a serde_json::Value, which can't carry raw bytes —
hence the base64 representation. Switching readFileSync to the status=2
raw-binary response is a cross-cutting protocol change that affects every
binary file read, so it was deferred rather than rushed (read was already 6.2×
faster from the pump fix in #77). Needs careful implementation + tests for:
binary readFile (sync + promises), writeFileBinary symmetry, and the
{__agentOsType:"bytes"} consumers elsewhere.

Expected impact

Removes base64 encode/decode + ~33% payload inflation per binary read; helps
read-heavy guests (bundlers, asset pipelines, large node_modules).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with crates/execution/src/v8_runtime.rs:183, crates/execution/assets/v8-bridge.source.js, and crates/v8-runtime/src/host_call.rs to trace the existing binary response paths. Inspect the other {__agentOsType:"bytes"} consumers, then add coverage for binary sync and promise reads plus writeFileBinary symmetry; done means binary reads use the raw-binary path without base64.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rust
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.