Skip to content

e2b: GET /v2/sandboxes re-reads runtime settings once per row #37

Description

@sweetcornna

The problem

GET /v2/sandboxes re-reads the runtime settings from SQLite once per row in the response.

infoView (control.ts:203-227) opens with:

const { sandboxDefaults } = readRuntimeSettings(db);

which is a real drizzle SELECT plus view conversion (settings.ts:75-87). The list route (control.ts:649) maps infoView over the whole page, and limit goes up to 1000 (control.ts:87) — so a polled endpoint runs the same query up to 1000 times per request for a value that is per-daemon and identical for every row.

Honest about the magnitude: the repo's own comments measure point reads in microseconds, so the worst case is roughly 1 ms on a 1000-row request, and the route's real cost is dominated by listSandboxes and the per-row JSON.parse. It is genuinely removable duplicate work, but the size of the win is marginal — filing it as a cleanup rather than a performance fix.

Proposed solution

Read once per request and pass it down: const { sandboxDefaults } = readRuntimeSettings(db) in the /v2/sandboxes handler (and the getInfo handler), with infoView taking sandboxDefaults as a parameter. O(page) becomes O(1).

Behaviour is unchanged — the liveness the current code buys ("a console change takes effect on the next request") still holds at per-request granularity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions