Throwaway prototypes for Sausage v3. Plan and decisions: ~/research/sausage-v3/PLAN.md. Results and evidence: the spike READMEs.
59 lines
3.0 KiB
Nu
59 lines
3.0 KiB
Nu
# Verify both WASI forms, render their bundles, and compare process wall times.
|
|
use std/assert
|
|
def checked [program: string, args: list<string>] {
|
|
let start = date now
|
|
let result = (run-external $program ...$args | complete)
|
|
let ms = ((date now) - $start) / 1ms
|
|
if $result.exit_code != 0 {
|
|
print $result.stdout
|
|
print --stderr $result.stderr
|
|
error make {msg: $'Failed: ($program) ($args | str join " ")'}
|
|
}
|
|
{ms: $ms, stdout: ($result.stdout | str trim)}
|
|
}
|
|
|
|
def main [] {
|
|
let root = '/tmp/s6-esbuild'
|
|
cd ($root | path join app)
|
|
^go version
|
|
^wasmtime --version
|
|
let flags = ['app.tsx' '--bundle' '--minify' '--format=iife' '--platform=browser' '--jsx=automatic' '--jsx-import-source=preact' '--legal-comments=none' '--log-level=error']
|
|
let variants = [
|
|
{name: native, program: $'($root)/esbuild-native', prefix: []},
|
|
{name: module, program: wasmtime, prefix: [run --dir .::/ $'($root)/esbuild.wasm']},
|
|
{name: component, program: wasmtime, prefix: [run --dir .::/ $'($root)/esbuild.component.wasm']}
|
|
]
|
|
for variant in $variants {
|
|
let version = checked $variant.program ($variant.prefix | append '--version')
|
|
assert equal $version.stdout '0.27.7'
|
|
print $'PASS ($variant.name) version=($version.stdout) first_startup_ms=($version.ms)'
|
|
let result = checked $variant.program ($variant.prefix | append $flags | append $'--outfile=($variant.name).js')
|
|
print $'PASS ($variant.name) first_bundle_ms=($result.ms)'
|
|
let render = checked node [check.mjs $'($variant.name).js']
|
|
print $render.stdout
|
|
}
|
|
assert equal (open --raw native.js) (open --raw module.js)
|
|
assert equal (open --raw native.js) (open --raw component.js)
|
|
print $'PASS byte-identical native/module/component bundles: ((ls component.js).size.0)'
|
|
for name in [esbuild-native esbuild.wasm esbuild.component.wasm] {
|
|
let size = (ls ($root | path join $name)).size.0
|
|
print $'SIZE ($name): ($size | into int) bytes'
|
|
}
|
|
# Precompiled artifacts model the host cache without including Cranelift compilation.
|
|
for name in [module component] {
|
|
let input = if $name == module { 'esbuild.wasm' } else { 'esbuild.component.wasm' }
|
|
let compile = checked wasmtime [compile $'($root)/($input)' -o $'($root)/($name).cwasm']
|
|
print $'COMPILE ($name): ($compile.ms) ms'
|
|
}
|
|
for variant in [
|
|
{name: native, program: $'($root)/esbuild-native', prefix: []},
|
|
{name: module-precompiled, program: wasmtime, prefix: [run --allow-precompiled --dir .::/ $'($root)/module.cwasm']},
|
|
{name: component-precompiled, program: wasmtime, prefix: [run --allow-precompiled --dir .::/ $'($root)/component.cwasm']}
|
|
] {
|
|
let startup = (1..5 | each { (checked $variant.program ($variant.prefix | append '--version')).ms })
|
|
let bundle = (1..5 | each { (checked $variant.program ($variant.prefix | append $flags | append '--outfile=bench.js')).ms })
|
|
print $'BENCH ($variant.name) median_ms n=5: startup=($startup | math median) bundle=($bundle | math median)'
|
|
}
|
|
print 'PASS all acceptance checks'
|
|
}
|