Skip to content

Reuse sandbox containers across build commands#127

Draft
syphar wants to merge 26 commits intorust-lang:mainfrom
syphar:reuse-container
Draft

Reuse sandbox containers across build commands#127
syphar wants to merge 26 commits intorust-lang:mainfrom
syphar:reuse-container

Conversation

@syphar
Copy link
Copy Markdown
Member

@syphar syphar commented May 4, 2026

doing some tests I realised that only docker create and docker rm sometimes takes 5-10s (also very often it's <100ms).

Docs.rs is running multiple commands:

  1. coverage
  2. docs
  3. json

for each target.

This leads me to the assumption that this could be a major reason why there is such a big difference between local builds and docs.rs builds for the same crate. The numbers roughly fit, #125 will give us more data.

Between these commands, we don't need a new container, we can just run more commands in the same container. This refactors rustwide into supporting this.

This also changes the memory-peak metric to be per-sandbox (= per container), and not per-command / call. Our source in docker is exactly that, and the API should reflect it. This is fine for the optimized docs.rs usage. Any

TODO

  • decide how backwards compatible we want / need to stay
  • test with docs.rs itself.
  • changelog, document breaking changes

syphar added 5 commits May 4, 2026 10:22
Attempt both sandbox container deletions during cleanup so one delete failure does not leak the other cached container.
Reuse a single sandbox container and enforce a fixed source mount kind across reused commands.
Move source mount mode selection from per-command state into SandboxBuilder so reusable sandboxes have a single fixed mount configuration.
Remove the unused sandbox mode without fixed directories and make start() construct the reusable session form directly.
@syphar syphar self-assigned this May 4, 2026
@syphar syphar changed the title WIP: reuse containers across build commands Reuse sandbox containers across build commands May 4, 2026
syphar added 10 commits May 4, 2026 18:02
Avoid rebuilding an ephemeral container when the command workdir is
inside the sandbox source tree.
Document the reused-container model and its callback
limitations, and keep failed `docker rm` calls from hiding
the leaked container ID during cleanup.
Create the container during sandbox startup so Docker failures surface
before the first command, and reuse the same helper when recreating a
stopped container.
Run sandboxed commands from the sandbox source directory by default
instead of forcing ".". This keeps explicit workdirs inside the source
tree and preserves the runtime panic for paths that escape it.
Summarize the new container reuse behavior and the breaking API
changes in the unreleased notes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant