TypeScript Runtime
Technical deep-dive on how the .polybench TypeScript runtime project works
Technical deep-dive on how the .polybench TypeScript runtime project works
This page documents how the .polybench/runtime-env/ts/ project is set up, how codegen works, and how execution is performed.
The TypeScript runtime generates an ES module (bench.mjs) and executes it with Node.js. There is no separate compilation step — Node runs the generated JavaScript directly. The runtime crate is runtimes-ts; templates come from poly-bench-project. TypeScript is the only runtime that runs npm install during init.
When you run poly-bench init with TypeScript enabled, poly-bench creates the runtime environment and runs npm install immediately. Specifically:
.polybench/runtime-env/ts/package.json with "type": "module", @types/node, typescript, and typescript-language-server as dev dependenciestsconfig.json with moduleResolution: "bundler", target: "ES2022", and noEmit: truenpm install immediatelyTypeScript is the only runtime that installs dependencies at init. This is because typescript-language-server must be available for LSP to work as soon as you open a .bench file. Other runtimes defer install to poly-bench build or poly-bench install.
npm install during init, so typescript-language-server is available immediately for LSP.When you run poly-bench build or poly-bench install:
package.json and tsconfig.json if --force is used[ts] dependencies in polybench.toml to package.jsonnpm install (skipped with --skip-install)"type": "module" — Generated code uses ES module syntax (import/export). Node runs bench.mjs directly with no bundler or transpilation at run time.moduleResolution: "bundler" — No actual bundler is used; this setting satisfies TypeScript's type checker and LSP for modern resolution while execution remains plain Node.typescript-language-server is available immediately for editor hover, completion, and diagnostics; without it, LSP would fail until the user runs poly-bench build..polybench/runtime-env/ts/node_modules/. No pollution of the project root.When you run poly-bench init --languages ts or poly-bench build, the following is created in .polybench/runtime-env/ts/:
| File | Source | Purpose |
|---|---|---|
package.json | templates.package_json() | Project config, "type": "module", dependencies including typescript-language-server |
tsconfig.json | templates.tsconfig_json() | moduleResolution: "bundler", no actual bundler — direct Node execution |
node_modules/ | npm install at init | Installed dependencies |
The package.json uses "type": "module" for ES modules. The tsconfig uses moduleResolution: "bundler" for tooling compatibility; execution is direct Node.
When poly-bench run executes a benchmark, the TypeScript runtime:
generate_standalone_script(spec, suite) in runtimes-ts/src/codegen.rsbench.mjs in the project rootFor poly-bench check, the runtime generates bench_check_<name>.ts and runs tsc to type-check.
Generated filenames:
bench.mjsbench_check_<name>.ts| Step | Command | Output |
|---|---|---|
| Run | — | No build; Node executes bench.mjs directly |
| Check | tsc --noEmit on generated .ts | Type-check only |
bench.mjs to project root, cache script path and source hashnode bench.mjs with ANVIL_RPC_URL in env if std::anvil is usedThe script is a self-contained ES module. It uses performance.now() or equivalent for timing and prints results to stdout.
moduleResolution: "bundler" setting is for tooling compatibility; execution is direct Node with no actual bundler.npm install during init; others defer to build or install.See Requirements — TypeScript for user-facing setup and gotchas.