From f6989255fe4c9d5a8290b25e0e5bd858447417ac Mon Sep 17 00:00:00 2001 From: x_ror <16686943+x-ror@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:59:39 +0200 Subject: [PATCH] feat(runtime): let a page be opened on the Web global surface page_runner_open and page_dispatcher_submit take a trailing `surface: Global_Surface = .Node` and hand it to page_open. A `.Web` page cannot reach process, require, Buffer or the other Node names (#5). The default stays `.Node`, so every existing page is unchanged. bench/pages opens its pages on `.Web` when BENCH_SURFACE=web. No test in this commit: tests are paused for this phase. Co-Authored-By: Claude Fable 5.2 --- bench/pages/main.odin | 15 +++++++++++---- pkg/runtime/page_dispatcher.odin | 6 +++++- pkg/runtime/page_runner.odin | 8 +++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/bench/pages/main.odin b/bench/pages/main.odin index d433742..8996e1f 100644 --- a/bench/pages/main.odin +++ b/bench/pages/main.odin @@ -81,6 +81,12 @@ rss_kb :: proc() -> int { // Every page the bench opens carries one of these as user_data, so every completion // is counted — the cold and warm rounds too, not only the churn. A round with // `total` 0 never refills; the churn round reopens until `total` pages have run. +// The global surface every bench page opens on. `.Node` unless BENCH_SURFACE=web, +// which measures the same pages without the Node names (and without stdio and the +// node-streams stack compiling at start-up). The page sources name no Node global, +// so they run unchanged on both. +bench_surface: lava.Global_Surface + Round :: struct { opened, finished, failed, total: int, limits: lava.Page_Limits, @@ -101,7 +107,7 @@ discard :: proc(runner: ^lava.Page_Runner, user_data: rawptr, result: lava.Resul } if r.opened < r.total { r.opened += 1 - lava.page_runner_open(runner, r.source, "", r.limits, r) + lava.page_runner_open(runner, r.source, "", r.limits, r, bench_surface) } lava.result_destroy(&result) } @@ -112,11 +118,12 @@ discard :: proc(runner: ^lava.Page_Runner, user_data: rawptr, result: lava.Resul // whether these were really pages is only known from `r.failed` after the round runs. open_n :: proc(runner: ^lava.Page_Runner, r: ^Round, n: int, source: string) -> f64 { start := time.tick_now() - for _ in 0 ..< n do lava.page_runner_open(runner, source, "", r.limits, r) + for _ in 0 ..< n do lava.page_runner_open(runner, source, "", r.limits, r, bench_surface) return time.duration_milliseconds(time.tick_since(start)) / f64(n) } main :: proc() { + if v, ok := os.lookup_env("BENCH_SURFACE", context.temp_allocator); ok && v == "web" do bench_surface = .Web if len(os.args) < 2 { fmt.eprintln("usage: bench-pages [total] [budget] [heap_every] [trivial|heavy] | dispatch [total]") os.exit(2) @@ -172,7 +179,7 @@ main :: proc() { start := time.tick_now() for _ in 0 ..< min(n, total) { churn.opened += 1 - lava.page_runner_open(&runner, shape, "", limits, &churn) + lava.page_runner_open(&runner, shape, "", limits, &churn, bench_surface) } lava.page_runner_run(&runner) secs := time.duration_seconds(time.tick_since(start)) @@ -234,7 +241,7 @@ dispatch_main :: proc() { start := time.tick_now() refused := 0 for _ in 0 ..< total { - if !lava.page_dispatcher_submit(&d, TRIVIAL, "", BENCH_LIMITS, &tally) do refused += 1 + if !lava.page_dispatcher_submit(&d, TRIVIAL, "", BENCH_LIMITS, &tally, bench_surface) do refused += 1 } for sync.atomic_load(&tally.done) < total - refused do time.sleep(time.Millisecond) secs := time.duration_seconds(time.tick_since(start)) diff --git a/pkg/runtime/page_dispatcher.odin b/pkg/runtime/page_dispatcher.odin index 27f6860..0d65361 100644 --- a/pkg/runtime/page_dispatcher.odin +++ b/pkg/runtime/page_dispatcher.odin @@ -74,6 +74,7 @@ Dispatch_Job :: struct { source_name: string, limits: Page_Limits, user_data: rawptr, + surface: Global_Surface, } @(private = "file") @@ -217,6 +218,7 @@ page_dispatcher_init :: proc( // Params: // source, source_name Copied through the dispatcher's allocator; the caller's // strings may go away as soon as this returns. +// surface As page_runner_open's; `.Node` by default. // limits As page_runner_open's: a page without a CPU budget is still // accepted, and reported .Invalid_Input through on_done — one // path for every per-page failure. @@ -230,6 +232,7 @@ page_dispatcher_submit :: proc( source, source_name: string, limits: Page_Limits, user_data: rawptr = nil, + surface: Global_Surface = .Node, ) -> bool { // A zero dispatcher has no allocator to copy through; it is Closed anyway. if d.allocator.procedure == nil do return false @@ -247,6 +250,7 @@ page_dispatcher_submit :: proc( source_name = name, limits = limits, user_data = user_data, + surface = surface, } if serr != nil || nerr != nil { job_free(d, job) @@ -486,7 +490,7 @@ worker_loop :: proc(w: ^Dispatch_Worker) { for page_runner_live(&w.runner) < d.pages_per_thread { job := worker_pop(w) if job == nil do break - page_runner_open(&w.runner, job.source, job.source_name, job.limits, job) + page_runner_open(&w.runner, job.source, job.source_name, job.limits, job, job.surface) } // Done once nothing is live. That also means the inbox is empty — the open loop // above stops only at a full runner or an empty inbox — and it stays empty: diff --git a/pkg/runtime/page_runner.odin b/pkg/runtime/page_runner.odin index aba2682..fd2a3a9 100644 --- a/pkg/runtime/page_runner.odin +++ b/pkg/runtime/page_runner.odin @@ -194,12 +194,18 @@ page_runner_destroy :: proc(runner: ^Page_Runner) { // "a page that spins is killed alone" hold for every caller. Negative and // NaN read as "no budget" to vm_set_cpu_budget, and are refused alike. // Pinned by runner_refuses_a_page_without_a_cpu_budget. +// surface The global names the page can reach (Global_Surface, runtime.odin). +// `.Node` by default; `.Web` hides process, require, Buffer and the rest +// (#5). Each page gets a fresh global in its pooled VM, so pages of both +// surfaces can take turns in one VM. Pinned by +// runner_web_page_sees_no_node_names_in_a_reused_vm. page_runner_open :: proc( runner: ^Page_Runner, source: string, source_name: string, limits: Page_Limits, user_data: rawptr = nil, + surface: Global_Surface = .Node, ) { context.allocator = runner.allocator defer free_all(context.temp_allocator) @@ -226,7 +232,7 @@ page_runner_open :: proc( append(&runner.pages, rp) index := len(runner.pages) - 1 - if !page_open(&rp.page, source, source_name, rp.loop, false, nil, limits, &runner.pool, runner_page = true) { + if !page_open(&rp.page, source, source_name, rp.loop, false, nil, limits, &runner.pool, runner_page = true, surface = surface) { runner_finish(runner, index, deliver = false) return }