ostia 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{chunk-85cap0sk.js → chunk-5qtsmr3p.js} +1 -1
- package/{chunk-8m8jb8gw.js → chunk-n02qf2mf.js} +8 -8
- package/cli.js +1 -1
- package/index.d.ts +13 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/runner.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{T,e,M,S,n,U,g,t,L,te,h,_,f,a,j,H,V,re,G,b,r,I,se,w,y,oe,c,k,s,l,d,z,O,ae,D,N}from"./chunk-8m8jb8gw.js";function Xe(u,R,x){let C=u[0];if(C==="bun"||C?.endsWith("/bun"))return{argv:[C,...R,...u.slice(1)],env:x};return{argv:u,env:{...process.env,...x,BUN_OPTIONS:R.join(" ")}}}function Zn(u){return u.startsWith("file://")?u.slice(7):u}function Ze(u,R,x){let C=u.nodes,J=C.length,fe=new Map,ie=[],ee=new Map,he=new Int32Array(J);for(let be=0;be<J;be++){let Ce=C[be],ke=Ce.callFrame,Re=Zn(ke.url),ve=fe.get(ke.functionName);if(ve===void 0)ve=new Map,fe.set(ke.functionName,ve);let Te=ve.get(Re);if(Te===void 0)Te=ie.length,ve.set(Re,Te),ie.push({key:e("fr",ke.functionName,Re),name:ke.functionName,url:Re||void 0,line:ke.lineNumber>=0?ke.lineNumber:void 0,col:ke.columnNumber>=0?ke.columnNumber:void 0});he[be]=Te,ee.set(Ce.id,be)}let pe=Array(J);for(let be=0;be<J;be++){let Ce=C[be];pe[be]={id:Ce.id,frameIx:he[ee.get(Ce.id)],children:Ce.children??[]}}let ge=new Float64Array(J),xe=new Float64Array(J),{samples:we,timeDeltas:ye}=u;for(let be=0;be<we.length;be++){let Ce=ee.get(we[be]);if(Ce===void 0)continue;ge[Ce]+=ye[be]??0,xe[Ce]+=1}let Pe=new Int32Array(J).fill(-1);for(let be=0;be<J;be++){let Ce=C[be].children;if(!Ce)continue;for(let ke of Ce){let Re=ee.get(ke);if(Re!==void 0)Pe[Re]=be}}let $e=[],Me=[];for(let be=J-1;be>=0;be--)if(Pe[be]===-1)Me.push(be);while(Me.length>0){let be=Me.pop();$e.push(be);let Ce=C[be].children;if(!Ce)continue;for(let ke of Ce){let Re=ee.get(ke);if(Re!==void 0&&Pe[Re]===be)Me.push(Re)}}let Ie=new Float64Array(J);for(let be=$e.length-1;be>=0;be--){let Ce=$e[be];Ie[Ce]+=ge[Ce];let ke=Pe[Ce];if(ke>=0)Ie[ke]+=Ie[Ce]}let Oe=Array(ie.length),Se=[];for(let be=0;be<J;be++){let Ce=pe[be].frameIx,ke=Oe[Ce];if(ke)ke.selfUs+=ge[be],ke.totalUs+=Ie[be],ke.samples+=xe[be];else{let Re={frameIx:Ce,selfUs:ge[be],totalUs:Ie[be],samples:xe[be]};Oe[Ce]=Re,Se.push(Re)}}return{origin:R,samplingIntervalUs:x,frames:ie,nodes:pe,totals:Se.sort((be,Ce)=>Ce.selfUs-be.selfUs),samples:{nodeIds:u.samples,timeDeltasUs:u.timeDeltas}}}async function fn(u){let R=`${u.artifactDir}/${u.fileName}`,{argv:x,env:C}=Xe(u.argv,["--cpu-prof","--cpu-prof-dir",u.artifactDir,"--cpu-prof-name",u.fileName,"--cpu-prof-interval",String(u.intervalUs)],u.env),J=Bun.nanoseconds(),ie=await Bun.spawn(x,{cwd:u.cwd,env:C,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,ee=Bun.nanoseconds()-J,he=Bun.file(R);if(!await he.exists())return{diagnosticWallNs:ee,exitCode:ie,warnings:[{code:"artifact-missing",message:`Expected a .cpuprofile at ${R} after exit ${ie}, found nothing. The workload's argv[0] must be a \`bun\` binary for CPU capture.`,data:{artifactPath:R,argv:u.argv}}]};let pe=await he.json(),ge=Ze(pe,"cpu-prof",u.intervalUs),xe=pe.samples.length===0?[{code:"empty-profile",message:"CPU capture produced zero samples."}]:[];return{diagnosticWallNs:ee,exitCode:ie,artifactPath:R,cpu:ge,warnings:xe}}function gn(u){let{node_fields:x,node_types:C}=u.snapshot.meta,J=x.indexOf("type"),fe=x.indexOf("self_size"),ie=x.length,ee=C[0];if(J===-1||fe===-1||!Array.isArray(ee))return{origin:"heap-prof",typeCounts:[],objectCount:u.snapshot.node_count};let he=ee.length,pe=Array(he),ge=new Map,xe=[],we=0,ye=u.nodes,Pe=ye.length;for(let Se=0;Se<Pe;Se+=ie){let be=ye[Se+J],Ce=ye[Se+fe]??0;we+=Ce;let ke;if(be>=0&&be<he){if(ke=pe[be],ke===void 0)ke={type:ee[be],count:0,bytes:0},pe[be]=ke,xe.push(ke)}else{let Re=`unknown(${be})`;if(ke=ge.get(Re),ke===void 0)ke={type:Re,count:0,bytes:0},ge.set(Re,ke),xe.push(ke)}ke.count++,ke.bytes+=Ce}let $e=xe.sort((Se,be)=>be.count-Se.count),Me=$e.slice(0,20),Ie=$e.slice(20),Oe=Me.map(({type:Se,count:be,bytes:Ce})=>({type:Se,count:be,retainedBytes:Ce}));if(Ie.length>0){let Se=0,be=0;for(let Ce of Ie)Se+=Ce.count,be+=Ce.bytes;Oe.push({type:"other",count:Se,retainedBytes:be})}return{origin:"heap-prof",heapSizeBytes:we,objectCount:u.snapshot.node_count,typeCounts:Oe}}async function hn(u){let R=`${u.artifactDir}/${u.fileName}`,{argv:x,env:C}=Xe(u.argv,["--heap-prof","--heap-prof-dir",u.artifactDir,"--heap-prof-name",u.fileName],u.env),J=Bun.nanoseconds(),ie=await Bun.spawn(x,{cwd:u.cwd,env:C,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,ee=Bun.nanoseconds()-J,he=Bun.file(R);if(!await he.exists())return{diagnosticWallNs:ee,exitCode:ie,warnings:[{code:"artifact-missing",message:`Expected a heap snapshot at ${R} after exit ${ie}, found nothing. The workload's argv[0] must be a \`bun\` binary for heap capture.`,data:{artifactPath:R,argv:u.argv}}]};let pe=await he.json(),ge=gn(pe);return{diagnosticWallNs:ee,exitCode:ie,artifactPath:R,heap:ge,warnings:[]}}var et=1000;async function bn(u,R={}){let x=R.intervalUs??et,{Session:C}=await import("inspector/promises"),J=new C;J.connect();let fe=Bun.nanoseconds();try{await J.post("Profiler.enable"),await J.post("Profiler.setSamplingInterval",{interval:x}),await J.post("Profiler.start");let ie=await u(),{profile:ee}=await J.post("Profiler.stop"),he=Bun.nanoseconds()-fe,pe=Ze(ee,"inspector",x);return{result:ie,cpu:pe,diagnosticWallNs:he}}finally{J.disconnect()}}function nt(u){let R=u>>>0;return()=>{R=R+1831565813|0;let x=Math.imul(R^R>>>15,1|R);return x=x+Math.imul(x^x>>>7,61|x)^x,((x^x>>>14)>>>0)/4294967296}}var en=2000,tt=2000;function rt(u){let R=u.length,x=R>>1;return R%2===0?(u[x-1]+u[x])/2:u[x]}function wn(u,R,x){if(u.length<=x)return u;let C=[...u];for(let J=0;J<x;J++){let fe=J+Math.floor(R()*(C.length-J)),ie=C[J];C[J]=C[fe],C[fe]=ie}return C.slice(0,x)}class an{sorted;rankOf;counts;n;constructor(u){let R=u.length,x=new Uint32Array(R);for(let C=0;C<R;C++)x[C]=C;x.sort((C,J)=>u[C]-u[J]),this.sorted=new Float64Array(R),this.rankOf=new Uint32Array(R);for(let C=0;C<R;C++)this.sorted[C]=u[x[C]],this.rankOf[x[C]]=C;this.n=R,this.counts=new Uint32Array(R)}resampleMedian(u){let{n:R,counts:x,sorted:C,rankOf:J}=this;x.fill(0);for(let pe=0;pe<R;pe++)x[J[Math.floor(u()*R)]]++;let fe=R+1>>1,ie=R%2===0?fe+1:fe,ee=0,he=-1;for(let pe=0;pe<R;pe++){if(ee+=x[pe],he<0&&ee>=fe)he=pe;if(ee>=ie)return he===pe?C[pe]:(C[he]+C[pe])/2}return C[R-1]}}function it(u,R){let x=new Float64Array(u.length+R.length+1);return x.set(u),x[u.length]=Number.NaN,x.set(R,u.length+1),Bun.hash.crc32(x)}function yn(u,R,x={}){let C=x.seed??it(u,R),J=nt(C),fe=x.iterations??tt,ie=u.length>en||R.length>en,ee=new an(wn(u,J,en)),he=new an(wn(R,J,en)),pe=rt(ee.sorted),ge=new Float64Array(fe);for(let xe=0;xe<fe;xe++){let we=ee.resampleMedian(J),ye=he.resampleMedian(J);ge[xe]=pe===0?ye-we===0?0:1/0:(ye-we)/pe*100}return ge.sort(),{ci95:[a(ge,0.025),a(ge,0.975)],seed:C,data:{subsampled:ie,iterations:fe}}}function st(u){let R=u<0?-1:1,x=Math.abs(u),C=0.254829592,J=-0.284496736,fe=1.421413741,ie=-1.453152027,ee=1.061405429,he=0.3275911,pe=1/(1+0.3275911*x),ge=1-((((1.061405429*pe+-1.453152027)*pe+1.421413741)*pe+-0.284496736)*pe+0.254829592)*pe*Math.exp(-x*x);return R*ge}function ot(u){return 0.5*(1+st(u/Math.SQRT2))}function xn(u,R){let x=u.length,C=R.length,J=x+C,fe=new Float64Array(u),ie=new Float64Array(R);fe.sort(),ie.sort();let ee=0,he=0,pe=0,ge=0,xe=0;while(pe<x||ge<C){let Ie=ge>=C||pe<x&&fe[pe]<=ie[ge]?fe[pe]:ie[ge],Oe=0;while(pe<x&&fe[pe]===Ie)Oe++,pe++;let Se=0;while(ge<C&&ie[ge]===Ie)Se++,ge++;let be=Oe+Se,Ce=xe+(be+1)/2;if(ee+=Oe*Ce,be>1)he+=be**3-be;xe+=be}let we=ee-x*(x+1)/2,ye=x*C/2,Pe=Math.sqrt(x*C*(J+1-he/(J*(J-1)))/12),$e=Pe===0?0:(we-ye)/Pe,Me=Math.min(1,Math.max(0,2*(1-ot(Math.abs($e)))));return{u:we,z:$e,pValue:Me}}var m={timingPct:5,frameSelfPct:10,heapTypePct:10,minFrameSelfUs:1000,alpha:0.01,bootstrapIterations:2000},mn=5;function nn(u,R){if(u===0)return R===0?0:1/0;return(R-u)/u*100}function Pn(u){let R=new Map;for(let x of u.measurements){let C=`${x.workloadId}\x00${x.phase}`;if(!R.has(C))R.set(C,x)}return R}function at(u,R,x){return{base:u,cand:R,baseByPhase:Pn(u),candByPhase:Pn(R),candWorkloads:new Map(R.workloads.map((C)=>[C.id,C])),environmentMismatch:mt(u,R),effectiveTimingPct:Math.max(x.timingPct,u.environment?.noise.floorPct??0,R.environment?.noise.floorPct??0)}}function mt(u,R){let x=[];if(u.platform.os!==R.platform.os)x.push({field:"platform.os",base:u.platform.os,cand:R.platform.os});if(u.platform.arch!==R.platform.arch)x.push({field:"platform.arch",base:u.platform.arch,cand:R.platform.arch});if(u.bunVersion!==R.bunVersion)x.push({field:"bunVersion",base:u.bunVersion,cand:R.bunVersion});if(u.environment&&R.environment){if(u.environment.cpuModel!==R.environment.cpuModel)x.push({field:"cpuModel",base:u.environment.cpuModel,cand:R.environment.cpuModel});if(u.environment.cores!==R.environment.cores)x.push({field:"cores",base:u.environment.cores,cand:R.environment.cores})}if(x.length===0)return;return{code:"environment-mismatch",message:`Base and candidate were measured on different environments (${x.map((C)=>C.field).join(", ")}); a timing delta may reflect that instead of the code change.`,data:{fields:x}}}function ct(u){let R=[];for(let C of u){if(!C.timing)continue;let J=1+C.timing.medianDeltaPct/100;if(Number.isFinite(J)&&J>0)R.push(Math.log(J))}if(R.length===0)return null;let x=R.reduce((C,J)=>C+J,0)/R.length;return(Math.exp(x)-1)*100}function q(u,R,x=m){let C=at(u,R,x);return{effectiveTimingPct:C.effectiveTimingPct,compare:(J)=>ut(C,J,x),unmatched(){let J=new Set(u.workloads.map((fe)=>fe.id));return{baseOnly:u.workloads.filter((fe)=>!C.candWorkloads.has(fe.id)),candOnly:R.workloads.filter((fe)=>!J.has(fe.id))}}}}function K(u,R){let x=0,C=0,J=0;for(let fe of u){if(!fe.timing)continue;if(fe.timing.verdict==="regressed")x++;else if(fe.timing.verdict==="improved")C++;else J++}return{matched:u.length,regressed:x,improved:C,unchanged:J,geomeanPct:ct(u),effectiveTimingPct:R,verdict:u.some((fe)=>fe.verdict==="fail")?"fail":"pass"}}function F(u,R,x=m){let C=q(u,R,x),J=[];for(let fe of u.workloads){let ie=C.compare(fe.id);if(ie)J.push(ie)}return{comparisons:J,unmatched:C.unmatched(),summary:K(J,C.effectiveTimingPct)}}function ut(u,R,x){let{baseByPhase:C,candByPhase:J,effectiveTimingPct:fe}=u,ie=C.get(`${R}\x00timing`),ee=J.get(`${R}\x00timing`),he=C.get(`${R}\x00cpu`),pe=J.get(`${R}\x00cpu`),ge=C.get(`${R}\x00heap`),xe=J.get(`${R}\x00heap`),we=u.candWorkloads.get(R),ye=ie?.id??he?.id??ge?.id,Pe=ee?.id??pe?.id??xe?.id??we?.id;if(!ye||!Pe)return;let $e=!1,Me=[];if(u.environmentMismatch)Me.push(u.environmentMismatch);let Ie;if(ie?.timing&&we?.skipped&&!ee?.timing)Ie={medianDeltaPct:0,meanDeltaPct:0,verdict:"unchanged"},Me.push({code:"skipped",message:"Candidate has no timing measurement for this workload (task.skip()); treated as unchanged.",data:{workloadId:R}});else if(ie?.timing&&ee?.timing){let be=ie.timing.samples,Ce=ee.timing.samples,ke=nn(ie.timing.median,ee.timing.median),Re=nn(ie.timing.mean,ee.timing.mean),ve=(Te,We)=>{if(Te>fe)return"regressed";if(We<-fe)return"improved";return"unchanged"};if(be.length<mn||Ce.length<mn){let Te=ve(ke,ke);if(Te==="regressed")$e=!0;Ie={medianDeltaPct:ke,meanDeltaPct:Re,verdict:Te},Me.push({code:"thin-comparison",message:`Only ${be.length} baseline / ${Ce.length} candidate sample(s); falling back to a point-estimate threshold instead of a bootstrap CI and Mann-Whitney test (needs ${mn}+ per side).`,data:{baseSamples:be.length,candSamples:Ce.length}})}else{let Te=yn(be,Ce,{iterations:x.bootstrapIterations}),We=xn(be,Ce),Ee=We.pValue<x.alpha?ve(Te.ci95[0],Te.ci95[1]):"unchanged";if(Ee==="regressed")$e=!0;Ie={medianDeltaPct:ke,meanDeltaPct:Re,ci95:Te.ci95,pValue:We.pValue,seed:Te.seed,verdict:Ee}}}let Oe;if(he?.cpu&&pe?.cpu){let be=new Map(he.cpu.totals.map((Te)=>[he.cpu.frames[Te.frameIx].key,Te])),Ce=new Map(pe.cpu.totals.map((Te)=>[pe.cpu.frames[Te.frameIx].key,Te])),ke=new Map(he.cpu.frames.map((Te)=>[Te.key,Te.name])),Re=new Map(pe.cpu.frames.map((Te)=>[Te.key,Te.name]));Oe=[...new Set([...be.keys(),...Ce.keys()])].map((Te)=>{let We=be.get(Te)?.selfUs??0,Ee=Ce.get(Te)?.selfUs??0;return{frameKey:Te,name:Re.get(Te)??ke.get(Te)??Te,baseSelfUs:We,candSelfUs:Ee,deltaPct:nn(We,Ee)}}).sort((Te,We)=>Math.abs(We.deltaPct)-Math.abs(Te.deltaPct));for(let Te of Oe)if((Te.baseSelfUs>=x.minFrameSelfUs||Te.candSelfUs>=x.minFrameSelfUs)&&Te.deltaPct>x.frameSelfPct)$e=!0}let Se;if(ge?.heap&&xe?.heap){let be=new Map(ge.heap.typeCounts.map((Re)=>[Re.type,Re])),Ce=new Map(xe.heap.typeCounts.map((Re)=>[Re.type,Re]));Se=[...new Set([...be.keys(),...Ce.keys()])].map((Re)=>{let ve=be.get(Re),Te=Ce.get(Re);return{type:Re,baseCount:ve?.count??0,candCount:Te?.count??0,baseBytes:ve?.retainedBytes,candBytes:Te?.retainedBytes,deltaPct:nn(ve?.count??0,Te?.count??0)}}).sort((Re,ve)=>Math.abs(ve.deltaPct)-Math.abs(Re.deltaPct));for(let Re of Se)if(Re.deltaPct>x.heapTypePct)$e=!0}return{id:e("cmp",ye,Pe),baselineMeasurementId:ye,candidateMeasurementId:Pe,timing:Ie,...Me.length>0&&{warnings:Me},frames:Oe,heapTypes:Se,thresholds:{...x,effectiveTimingPct:fe},verdict:$e?"fail":"pass"}}var qe="node_modules/.cache/ostia",lt=".ostia/baselines",dt={warmup:3,outDir:qe,baselineDir:lt,baseline:"main",thresholds:m,workloads:[]};class P extends Error{}var pt={runs:"samples"};function $n(u,R){for(let[x,C]of Object.entries(pt))if(x in u)throw new P(`${R}: "${x}" was renamed to "${C}".`);return{...dt,...u,thresholds:{...m,...u.thresholds??{}}}}async function kn(u){let R=Bun.file(u);if(!await R.exists())return;let x;try{x=await R.json()}catch(C){throw new P(`${u}: ${C instanceof Error?C.message:String(C)}`)}return $n(x,u)}async function Mn(u){let R=u.startsWith("/")?u:`${process.cwd()}/${u}`;if(!await Bun.file(R).exists())return;let x;try{x=await import(R)}catch(C){throw new P(`${u}: ${C instanceof Error?C.message:String(C)}`)}return $n(x.default??{},u)}async function E(u){if(u!==void 0)return u.endsWith(".ts")?Mn(u):kn(u);return await Mn("ostia.config.ts")??kn("ostia.config.json")}function o(u,R){return`${u.baselineDir}/${R??u.baseline}.json`}async function Y(){if(await Bun.file("ostia.config.ts").exists())return"ostia.config.ts";if(await Bun.file("ostia.config.json").exists())return"ostia.config.json";return}var ft=10,gt=3000000000,ht=3;function cn(u){if(u.timeSource)H(u.timeSource);let R=u.warmup??ht,x=u.samples,C=u.minSamples??ft,J=x??C,fe=x!==void 0?0:u.budgetMs!==void 0?u.budgetMs*1e6:gt,ie=u.timeSource!==void 0,ee=u.ignoreExitCodes??[],he=new Set(ee),pe=[],ge=0,xe=0,we=!1,ye;function Pe(){if(we)return!0;if(x!==void 0)return xe>=x;return xe>=J&&ge>=fe}async function $e(Me,Ie){if(u.prepare)await G(u.prepare,{phase:Me,index:Ie},{cwd:u.cwd,env:u.env,timeoutMs:u.timeoutMs,signal:u.signal});return re(u)}return{async warmup(){for(let Me=0;Me<R;Me++){if(u.signal?.aborted)return;await $e("warmup",Me)}},async step(){if(Pe()||u.signal?.aborted)return!1;let Me=await $e("timing",xe);if(u.signal?.aborted)return!1;if(Me.timeSourceNoMatch)ye??=Me.timeSourceMissOutput;if(pe.push({i:xe,wallNs:Me.wallNs,exitCode:Me.exitCode??void 0,userNs:Me.userNs,systemNs:Me.systemNs,maxRssBytes:Me.maxRssBytes,...Me.reportedNs!==void 0&&{reportedNs:Me.reportedNs},...Me.timedOut?{timedOut:!0}:{},...Me.timeSourceNoMatch?{timeSourceNoMatch:!0}:{}}),ge+=Me.wallNs,xe++,Me.exitCode!==null&&Me.exitCode!==0&&!he.has(Me.exitCode))we=!0;return!0},done:Pe,result(){let Me=pe.filter((ke)=>!ke.timedOut&&!ke.timeSourceNoMatch),Ie=Me.map((ke)=>ie?ke.reportedNs:ke.wallNs),Oe=[],Se=pe.filter((ke)=>ke.timedOut).length;if(Se>0)Oe.push({code:"timeout",message:`${Se} of ${pe.length} trial(s) timed out after ${u.timeoutMs}ms.`,data:{timeoutMs:u.timeoutMs,trials:Se}});let be=pe.filter((ke)=>ke.timeSourceNoMatch).length;if(be>0&&u.timeSource){let{pattern:ke}=u.timeSource;Oe.push({code:"time-source-no-match",message:`${be} of ${pe.length} trial(s) didn't match the timeSource pattern.`,data:{pattern:typeof ke==="string"?ke:ke.source,trials:be,...ye!==void 0&&{output:ye}}})}if(Ie.length===0)return{trials:pe,warnings:Oe};let Ce=f(Ie);return Oe.push(...j(Ce,Me.map((ke)=>ke.exitCode),ie?"reported":"subprocess",ee)),{trials:pe,timing:Ce,warnings:Oe}}}}async function un(u){await u.warmup();while(await u.step());}async function ne(u){let R=cn(u);return await un(R),R.result()}function B(u,R=[]){if(!u.timing)return!0;let x=new Set(R);return u.trials.some((C)=>C.exitCode!==void 0&&C.exitCode!==0&&!x.has(C.exitCode))}function tn(u,R){let x={samples:R.samples,minSamples:R.minSamples};for(let[C,J]of Object.entries(x))if(J!==void 0&&(!Number.isFinite(J)||J<1))throw RangeError(`${u}: ${C} must be >= 1, got ${J}`);if(R.budgetMs!==void 0&&!Number.isFinite(R.budgetMs))throw RangeError(`${u}: budgetMs must be finite, got ${R.budgetMs}`)}async function A(u,R){let x=new Set;for(let C of u)for await(let J of new Bun.Glob(C).scan({cwd:R,absolute:!1}))x.add(J);return[...x].sort()}var Rn=new URL("./runner.ts",import.meta.url).pathname;function Z(){return Math.max(1,navigator.hardwareConcurrency||1)}async function X(u,R){return A(u,R)}function bt(u){if(u===void 0)return;return u==="auto"?Z():u}async function W(u,R,x=process.cwd()){return{suites:u.suites.length>0?u.suites:R?.suites?await X(R.suites,x):[],budgetMs:u.budgetMs??R?.budgetMs,samples:u.samples??R?.samples,minSamples:u.minSamples??R?.minSamples,jobs:u.jobs??bt(R?.jobs),gc:u.gc??R?.gc??!1,cpu:u.cpu??R?.cpu??!1,alloc:u.alloc??R?.alloc??!1,filter:u.filter??R?.filter,isolate:u.isolate??R?.isolate??!1,preload:u.preload.length>0?u.preload:R?.preload??[],bunFlags:u.bunFlags.length>0?u.bunFlags:R?.bunFlags??[],outDir:u.outDir??R?.outDir,noiseCheck:u.noiseCheck,timeoutMs:u.timeoutMs??R?.timeoutMs,cwd:x}}async function v(u){tn("bench",u);let x=`${u.outDir??qe}/bench-tmp`,C=u.cwd??process.cwd(),J=Math.max(1,Math.floor(u.jobs??1)),fe={budgetMs:u.budgetMs,samples:u.samples,minSamples:u.minSamples,gc:u.gc,cpu:u.cpu,alloc:u.alloc,noiseCheck:!1},ie=u.noiseCheck===!1?void 0:l(),ee=ie?d(ie):void 0,he=(ye)=>ye.startsWith("/")?ye:`${C}/${ye}`,pe=u.suites.map(he),ge=(u.preload??[]).map(he),xe=u.bunFlags??[],we=async(ye,Pe)=>{let $e=new Set,Me=0,Ie,Oe=async()=>{while(Ie===void 0&&!u.signal?.aborted&&Me<ye.length){let Se=Me++;try{let be=V(u.timeoutMs,u.signal),Ce=Bun.spawn(ye[Se],{cwd:C,stdout:"inherit",stderr:"inherit",stdin:"ignore",...be.spawn});$e.add(Ce);let ke=await Ce.exited;if($e.delete(Ce),u.signal?.aborted)return;if(be.timedOut())throw Error(`Bench suite timed out after ${u.timeoutMs}ms: ${Pe(Se)}`);if(ke!==0)throw Error(`Bench suite failed: ${Pe(Se)} (runner exited ${ke})`)}catch(be){Ie??=be instanceof Error?be:Error(String(be));for(let Ce of $e)Ce.kill()}}};if(await Promise.all(Array.from({length:Math.min(J,ye.length)},Oe)),Ie)throw Ie};try{let ye=pe.map((ve)=>`${x}/${e("bench-plan",ve)}.json`),Pe=pe.map((ve)=>`${x}/${e("bench-primary",ve)}.json`),$e=pe.map((ve,Te)=>["bun",...xe,Rn,ve,Pe[Te],JSON.stringify({...fe,filter:u.filter,isolate:u.isolate,preload:ge,planPath:ye[Te]})]);await we($e,(ve)=>u.suites[ve]);let Me=await Promise.all(ye.map(async(ve)=>{if(!await Bun.file(ve).exists())return[];let{tasks:Te}=await Bun.file(ve).json();return Te})),Ie=await Promise.all(Pe.map(async(ve)=>await Bun.file(ve).exists()?s(ve):void 0)),Oe=[];for(let ve=0;ve<Me.length;ve++)for(let Te of Me[ve])if(Te.isolate)Oe.push({suiteIndex:ve,taskIds:[Te.id]});let Se=Oe.map((ve,Te)=>`${x}/${e("bench-item",pe[ve.suiteIndex],Te)}.json`),be=Oe.map((ve,Te)=>["bun",...xe,Rn,pe[ve.suiteIndex],Se[Te],JSON.stringify({...fe,taskIds:ve.taskIds,preload:ge,markIsolated:!0})]);await we(be,(ve)=>u.suites[Oe[ve].suiteIndex]);let Ce=await Promise.all(Se.map(async(ve)=>await Bun.file(ve).exists()?s(ve):void 0)),ke=[],Re=[];for(let ve=0;ve<Me.length;ve++){let Te=Ie[ve];if(!Te)continue;let We=new Map;for(let Be of Te.measurements){let De=We.get(Be.workloadId)??[];De.push(Be),We.set(Be.workloadId,De)}let Ee=0,Je=new Map;Oe.forEach((Be,De)=>{let Fe=Ce[De];if(Be.suiteIndex===ve&&Fe)Je.set(Be.taskIds[0],Fe)});for(let Be of Me[ve])if(Be.isolate){let De=Je.get(Be.id);if(!De)continue;let Fe=De.workloads[0];ke.push(Fe);for(let Ae of De.measurements)if(Ae.workloadId===Fe.id)Re.push(Ae)}else{let De=Te.workloads[Ee];ke.push(De),Ee++;for(let Fe of We.get(De.id)??[])Re.push(Fe)}}if(ee&&Re.length>0)Re[0].warnings=[...Re[0].warnings,ee];if(u.signal?.aborted&&Re.length>0){let ve=Re[Re.length-1];ve.warnings=[...ve.warnings,{code:"aborted",message:"Run was cancelled before it finished; this document holds whatever suites/tasks had already completed."}]}return r(ke,Re,ie)}finally{await Bun.spawn(["rm","-rf",x]).exited}}function ce(u,R,x=8){if(x<=1)throw RangeError(`range: multiplier must be > 1, got ${x}`);if(u<=0)throw RangeError(`range: start must be > 0, got ${u}`);let C=[];for(let J=u;J<=R;J*=x)C.push(J);if(!C.includes(R))C.push(R);return C}function je(u,R){if(R){let x=u.measurements.find((C)=>C.id===R);return x?.cpu?[x]:[]}return u.measurements.filter((x)=>x.phase==="cpu"&&x.cpu)}function He(u){let R=u.nodes,x=R.length,C=wt(u),J=new Int32Array(x).fill(-1);for(let he=0;he<x;he++)for(let pe of R[he].children){let ge=C(pe);if(ge!==-1)J[ge]=he}let fe=[];for(let he=0;he<x;he++)if(J[he]===-1)fe.push(he);let ie=[],ee=[];for(let he=fe.length-1;he>=0;he--)ee.push(fe[he]);while(ee.length>0){let he=ee.pop();ie.push(he);for(let pe of R[he].children){let ge=C(pe);if(ge!==-1&&J[ge]===he)ee.push(ge)}}return{count:x,indexOf:C,parentIx:J,roots:fe,order:ie}}function wt(u){let R=u.nodes,x=R.length,C=1/0,J=-1/0,fe=!0;for(let ee=0;ee<x;ee++){let he=R[ee].id;if(!Number.isInteger(he)){fe=!1;break}if(he<C)C=he;if(he>J)J=he}if(fe&&x>0&&J-C<x*4+64){let ee=J-C+1,he=new Int32Array(ee).fill(-1);for(let pe=0;pe<x;pe++)he[R[pe].id-C]=pe;return(pe)=>{let ge=pe-C;return ge>=0&&ge<ee?he[ge]:-1}}let ie=new Map;for(let ee=0;ee<x;ee++)ie.set(R[ee].id,ee);return(ee)=>ie.get(ee)??-1}function Cn(u,R){let{count:x,indexOf:C,parentIx:J,order:fe}=R,ie=new Float64Array(x),ee=new Float64Array(x),he=u.samples?.nodeIds??[],pe=u.samples?.timeDeltasUs??[];for(let xe=0;xe<he.length;xe++){let we=C(he[xe]);if(we===-1)continue;ie[we]+=pe[xe]??0,ee[we]+=1}let ge=new Float64Array(x);for(let xe=fe.length-1;xe>=0;xe--){let we=fe[xe];ge[we]+=ie[we];let ye=J[we];if(ye>=0)ge[ye]+=ge[we]}return{selfUs:ie,totalUs:ge,samples:ee}}var vn={name:"collapsed",async render(u,R={}){return{files:je(u,R.measurementId).map((J)=>{let fe=J.cpu,{nodes:ie,frames:ee}=fe,he=He(fe),pe=Array(he.count);for(let Pe of he.order){let $e=ee[ie[Pe].frameIx].name||"(anonymous)",Me=he.parentIx[Pe];pe[Pe]=Me===-1?$e:`${pe[Me]};${$e}`}let ge=new Float64Array(he.count),xe=[],we=fe.samples?.nodeIds??[];for(let Pe=0;Pe<we.length;Pe++){let $e=he.indexOf(we[Pe]);if($e===-1)continue;if(ge[$e]++===0)xe.push($e)}let ye=Array(xe.length);for(let Pe=0;Pe<xe.length;Pe++){let $e=xe[Pe];ye[Pe]=`${pe[$e]} ${ge[$e]}`}return{path:`${J.id}.collapsed.txt`,content:ye.join(`
|
|
2
|
+
import{T,e,M,S,n,U,g,t,L,te,h,_,f,a,j,H,V,re,G,b,r,I,se,w,y,oe,c,k,s,l,d,z,O,ae,D,N}from"./chunk-n02qf2mf.js";function Xe(u,R,x){let C=u[0];if(C==="bun"||C?.endsWith("/bun"))return{argv:[C,...R,...u.slice(1)],env:x};return{argv:u,env:{...process.env,...x,BUN_OPTIONS:R.join(" ")}}}function Zn(u){return u.startsWith("file://")?u.slice(7):u}function Ze(u,R,x){let C=u.nodes,J=C.length,fe=new Map,ie=[],ee=new Map,he=new Int32Array(J);for(let be=0;be<J;be++){let Ce=C[be],ke=Ce.callFrame,Re=Zn(ke.url),ve=fe.get(ke.functionName);if(ve===void 0)ve=new Map,fe.set(ke.functionName,ve);let Te=ve.get(Re);if(Te===void 0)Te=ie.length,ve.set(Re,Te),ie.push({key:e("fr",ke.functionName,Re),name:ke.functionName,url:Re||void 0,line:ke.lineNumber>=0?ke.lineNumber:void 0,col:ke.columnNumber>=0?ke.columnNumber:void 0});he[be]=Te,ee.set(Ce.id,be)}let pe=Array(J);for(let be=0;be<J;be++){let Ce=C[be];pe[be]={id:Ce.id,frameIx:he[ee.get(Ce.id)],children:Ce.children??[]}}let ge=new Float64Array(J),xe=new Float64Array(J),{samples:we,timeDeltas:ye}=u;for(let be=0;be<we.length;be++){let Ce=ee.get(we[be]);if(Ce===void 0)continue;ge[Ce]+=ye[be]??0,xe[Ce]+=1}let Pe=new Int32Array(J).fill(-1);for(let be=0;be<J;be++){let Ce=C[be].children;if(!Ce)continue;for(let ke of Ce){let Re=ee.get(ke);if(Re!==void 0)Pe[Re]=be}}let $e=[],Me=[];for(let be=J-1;be>=0;be--)if(Pe[be]===-1)Me.push(be);while(Me.length>0){let be=Me.pop();$e.push(be);let Ce=C[be].children;if(!Ce)continue;for(let ke of Ce){let Re=ee.get(ke);if(Re!==void 0&&Pe[Re]===be)Me.push(Re)}}let Ie=new Float64Array(J);for(let be=$e.length-1;be>=0;be--){let Ce=$e[be];Ie[Ce]+=ge[Ce];let ke=Pe[Ce];if(ke>=0)Ie[ke]+=Ie[Ce]}let Oe=Array(ie.length),Se=[];for(let be=0;be<J;be++){let Ce=pe[be].frameIx,ke=Oe[Ce];if(ke)ke.selfUs+=ge[be],ke.totalUs+=Ie[be],ke.samples+=xe[be];else{let Re={frameIx:Ce,selfUs:ge[be],totalUs:Ie[be],samples:xe[be]};Oe[Ce]=Re,Se.push(Re)}}return{origin:R,samplingIntervalUs:x,frames:ie,nodes:pe,totals:Se.sort((be,Ce)=>Ce.selfUs-be.selfUs),samples:{nodeIds:u.samples,timeDeltasUs:u.timeDeltas}}}async function fn(u){let R=`${u.artifactDir}/${u.fileName}`,{argv:x,env:C}=Xe(u.argv,["--cpu-prof","--cpu-prof-dir",u.artifactDir,"--cpu-prof-name",u.fileName,"--cpu-prof-interval",String(u.intervalUs)],u.env),J=Bun.nanoseconds(),ie=await Bun.spawn(x,{cwd:u.cwd,env:C,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,ee=Bun.nanoseconds()-J,he=Bun.file(R);if(!await he.exists())return{diagnosticWallNs:ee,exitCode:ie,warnings:[{code:"artifact-missing",message:`Expected a .cpuprofile at ${R} after exit ${ie}, found nothing. The workload's argv[0] must be a \`bun\` binary for CPU capture.`,data:{artifactPath:R,argv:u.argv}}]};let pe=await he.json(),ge=Ze(pe,"cpu-prof",u.intervalUs),xe=pe.samples.length===0?[{code:"empty-profile",message:"CPU capture produced zero samples."}]:[];return{diagnosticWallNs:ee,exitCode:ie,artifactPath:R,cpu:ge,warnings:xe}}function gn(u){let{node_fields:x,node_types:C}=u.snapshot.meta,J=x.indexOf("type"),fe=x.indexOf("self_size"),ie=x.length,ee=C[0];if(J===-1||fe===-1||!Array.isArray(ee))return{origin:"heap-prof",typeCounts:[],objectCount:u.snapshot.node_count};let he=ee.length,pe=Array(he),ge=new Map,xe=[],we=0,ye=u.nodes,Pe=ye.length;for(let Se=0;Se<Pe;Se+=ie){let be=ye[Se+J],Ce=ye[Se+fe]??0;we+=Ce;let ke;if(be>=0&&be<he){if(ke=pe[be],ke===void 0)ke={type:ee[be],count:0,bytes:0},pe[be]=ke,xe.push(ke)}else{let Re=`unknown(${be})`;if(ke=ge.get(Re),ke===void 0)ke={type:Re,count:0,bytes:0},ge.set(Re,ke),xe.push(ke)}ke.count++,ke.bytes+=Ce}let $e=xe.sort((Se,be)=>be.count-Se.count),Me=$e.slice(0,20),Ie=$e.slice(20),Oe=Me.map(({type:Se,count:be,bytes:Ce})=>({type:Se,count:be,retainedBytes:Ce}));if(Ie.length>0){let Se=0,be=0;for(let Ce of Ie)Se+=Ce.count,be+=Ce.bytes;Oe.push({type:"other",count:Se,retainedBytes:be})}return{origin:"heap-prof",heapSizeBytes:we,objectCount:u.snapshot.node_count,typeCounts:Oe}}async function hn(u){let R=`${u.artifactDir}/${u.fileName}`,{argv:x,env:C}=Xe(u.argv,["--heap-prof","--heap-prof-dir",u.artifactDir,"--heap-prof-name",u.fileName],u.env),J=Bun.nanoseconds(),ie=await Bun.spawn(x,{cwd:u.cwd,env:C,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,ee=Bun.nanoseconds()-J,he=Bun.file(R);if(!await he.exists())return{diagnosticWallNs:ee,exitCode:ie,warnings:[{code:"artifact-missing",message:`Expected a heap snapshot at ${R} after exit ${ie}, found nothing. The workload's argv[0] must be a \`bun\` binary for heap capture.`,data:{artifactPath:R,argv:u.argv}}]};let pe=await he.json(),ge=gn(pe);return{diagnosticWallNs:ee,exitCode:ie,artifactPath:R,heap:ge,warnings:[]}}var et=1000;async function bn(u,R={}){let x=R.intervalUs??et,{Session:C}=await import("inspector/promises"),J=new C;J.connect();let fe=Bun.nanoseconds();try{await J.post("Profiler.enable"),await J.post("Profiler.setSamplingInterval",{interval:x}),await J.post("Profiler.start");let ie=await u(),{profile:ee}=await J.post("Profiler.stop"),he=Bun.nanoseconds()-fe,pe=Ze(ee,"inspector",x);return{result:ie,cpu:pe,diagnosticWallNs:he}}finally{J.disconnect()}}function nt(u){let R=u>>>0;return()=>{R=R+1831565813|0;let x=Math.imul(R^R>>>15,1|R);return x=x+Math.imul(x^x>>>7,61|x)^x,((x^x>>>14)>>>0)/4294967296}}var en=2000,tt=2000;function rt(u){let R=u.length,x=R>>1;return R%2===0?(u[x-1]+u[x])/2:u[x]}function wn(u,R,x){if(u.length<=x)return u;let C=[...u];for(let J=0;J<x;J++){let fe=J+Math.floor(R()*(C.length-J)),ie=C[J];C[J]=C[fe],C[fe]=ie}return C.slice(0,x)}class an{sorted;rankOf;counts;n;constructor(u){let R=u.length,x=new Uint32Array(R);for(let C=0;C<R;C++)x[C]=C;x.sort((C,J)=>u[C]-u[J]),this.sorted=new Float64Array(R),this.rankOf=new Uint32Array(R);for(let C=0;C<R;C++)this.sorted[C]=u[x[C]],this.rankOf[x[C]]=C;this.n=R,this.counts=new Uint32Array(R)}resampleMedian(u){let{n:R,counts:x,sorted:C,rankOf:J}=this;x.fill(0);for(let pe=0;pe<R;pe++)x[J[Math.floor(u()*R)]]++;let fe=R+1>>1,ie=R%2===0?fe+1:fe,ee=0,he=-1;for(let pe=0;pe<R;pe++){if(ee+=x[pe],he<0&&ee>=fe)he=pe;if(ee>=ie)return he===pe?C[pe]:(C[he]+C[pe])/2}return C[R-1]}}function it(u,R){let x=new Float64Array(u.length+R.length+1);return x.set(u),x[u.length]=Number.NaN,x.set(R,u.length+1),Bun.hash.crc32(x)}function yn(u,R,x={}){let C=x.seed??it(u,R),J=nt(C),fe=x.iterations??tt,ie=u.length>en||R.length>en,ee=new an(wn(u,J,en)),he=new an(wn(R,J,en)),pe=rt(ee.sorted),ge=new Float64Array(fe);for(let xe=0;xe<fe;xe++){let we=ee.resampleMedian(J),ye=he.resampleMedian(J);ge[xe]=pe===0?ye-we===0?0:1/0:(ye-we)/pe*100}return ge.sort(),{ci95:[a(ge,0.025),a(ge,0.975)],seed:C,data:{subsampled:ie,iterations:fe}}}function st(u){let R=u<0?-1:1,x=Math.abs(u),C=0.254829592,J=-0.284496736,fe=1.421413741,ie=-1.453152027,ee=1.061405429,he=0.3275911,pe=1/(1+0.3275911*x),ge=1-((((1.061405429*pe+-1.453152027)*pe+1.421413741)*pe+-0.284496736)*pe+0.254829592)*pe*Math.exp(-x*x);return R*ge}function ot(u){return 0.5*(1+st(u/Math.SQRT2))}function xn(u,R){let x=u.length,C=R.length,J=x+C,fe=new Float64Array(u),ie=new Float64Array(R);fe.sort(),ie.sort();let ee=0,he=0,pe=0,ge=0,xe=0;while(pe<x||ge<C){let Ie=ge>=C||pe<x&&fe[pe]<=ie[ge]?fe[pe]:ie[ge],Oe=0;while(pe<x&&fe[pe]===Ie)Oe++,pe++;let Se=0;while(ge<C&&ie[ge]===Ie)Se++,ge++;let be=Oe+Se,Ce=xe+(be+1)/2;if(ee+=Oe*Ce,be>1)he+=be**3-be;xe+=be}let we=ee-x*(x+1)/2,ye=x*C/2,Pe=Math.sqrt(x*C*(J+1-he/(J*(J-1)))/12),$e=Pe===0?0:(we-ye)/Pe,Me=Math.min(1,Math.max(0,2*(1-ot(Math.abs($e)))));return{u:we,z:$e,pValue:Me}}var m={timingPct:5,frameSelfPct:10,heapTypePct:10,minFrameSelfUs:1000,alpha:0.01,bootstrapIterations:2000},mn=5;function nn(u,R){if(u===0)return R===0?0:1/0;return(R-u)/u*100}function Pn(u){let R=new Map;for(let x of u.measurements){let C=`${x.workloadId}\x00${x.phase}`;if(!R.has(C))R.set(C,x)}return R}function at(u,R,x){return{base:u,cand:R,baseByPhase:Pn(u),candByPhase:Pn(R),candWorkloads:new Map(R.workloads.map((C)=>[C.id,C])),environmentMismatch:mt(u,R),effectiveTimingPct:Math.max(x.timingPct,u.environment?.noise.floorPct??0,R.environment?.noise.floorPct??0)}}function mt(u,R){let x=[];if(u.platform.os!==R.platform.os)x.push({field:"platform.os",base:u.platform.os,cand:R.platform.os});if(u.platform.arch!==R.platform.arch)x.push({field:"platform.arch",base:u.platform.arch,cand:R.platform.arch});if(u.bunVersion!==R.bunVersion)x.push({field:"bunVersion",base:u.bunVersion,cand:R.bunVersion});if(u.environment&&R.environment){if(u.environment.cpuModel!==R.environment.cpuModel)x.push({field:"cpuModel",base:u.environment.cpuModel,cand:R.environment.cpuModel});if(u.environment.cores!==R.environment.cores)x.push({field:"cores",base:u.environment.cores,cand:R.environment.cores})}if(x.length===0)return;return{code:"environment-mismatch",message:`Base and candidate were measured on different environments (${x.map((C)=>C.field).join(", ")}); a timing delta may reflect that instead of the code change.`,data:{fields:x}}}function ct(u){let R=[];for(let C of u){if(!C.timing)continue;let J=1+C.timing.medianDeltaPct/100;if(Number.isFinite(J)&&J>0)R.push(Math.log(J))}if(R.length===0)return null;let x=R.reduce((C,J)=>C+J,0)/R.length;return(Math.exp(x)-1)*100}function q(u,R,x=m){let C=at(u,R,x);return{effectiveTimingPct:C.effectiveTimingPct,compare:(J)=>ut(C,J,x),unmatched(){let J=new Set(u.workloads.map((fe)=>fe.id));return{baseOnly:u.workloads.filter((fe)=>!C.candWorkloads.has(fe.id)),candOnly:R.workloads.filter((fe)=>!J.has(fe.id))}}}}function K(u,R){let x=0,C=0,J=0;for(let fe of u){if(!fe.timing)continue;if(fe.timing.verdict==="regressed")x++;else if(fe.timing.verdict==="improved")C++;else J++}return{matched:u.length,regressed:x,improved:C,unchanged:J,geomeanPct:ct(u),effectiveTimingPct:R,verdict:u.some((fe)=>fe.verdict==="fail")?"fail":"pass"}}function F(u,R,x=m){let C=q(u,R,x),J=[];for(let fe of u.workloads){let ie=C.compare(fe.id);if(ie)J.push(ie)}return{comparisons:J,unmatched:C.unmatched(),summary:K(J,C.effectiveTimingPct)}}function ut(u,R,x){let{baseByPhase:C,candByPhase:J,effectiveTimingPct:fe}=u,ie=C.get(`${R}\x00timing`),ee=J.get(`${R}\x00timing`),he=C.get(`${R}\x00cpu`),pe=J.get(`${R}\x00cpu`),ge=C.get(`${R}\x00heap`),xe=J.get(`${R}\x00heap`),we=u.candWorkloads.get(R),ye=ie?.id??he?.id??ge?.id,Pe=ee?.id??pe?.id??xe?.id??we?.id;if(!ye||!Pe)return;let $e=!1,Me=[];if(u.environmentMismatch)Me.push(u.environmentMismatch);let Ie;if(ie?.timing&&we?.skipped&&!ee?.timing)Ie={medianDeltaPct:0,meanDeltaPct:0,verdict:"unchanged"},Me.push({code:"skipped",message:"Candidate has no timing measurement for this workload (task.skip()); treated as unchanged.",data:{workloadId:R}});else if(ie?.timing&&ee?.timing){let be=ie.timing.samples,Ce=ee.timing.samples,ke=nn(ie.timing.median,ee.timing.median),Re=nn(ie.timing.mean,ee.timing.mean),ve=(Te,We)=>{if(Te>fe)return"regressed";if(We<-fe)return"improved";return"unchanged"};if(be.length<mn||Ce.length<mn){let Te=ve(ke,ke);if(Te==="regressed")$e=!0;Ie={medianDeltaPct:ke,meanDeltaPct:Re,verdict:Te},Me.push({code:"thin-comparison",message:`Only ${be.length} baseline / ${Ce.length} candidate sample(s); falling back to a point-estimate threshold instead of a bootstrap CI and Mann-Whitney test (needs ${mn}+ per side).`,data:{baseSamples:be.length,candSamples:Ce.length}})}else{let Te=yn(be,Ce,{iterations:x.bootstrapIterations}),We=xn(be,Ce),Ee=We.pValue<x.alpha?ve(Te.ci95[0],Te.ci95[1]):"unchanged";if(Ee==="regressed")$e=!0;Ie={medianDeltaPct:ke,meanDeltaPct:Re,ci95:Te.ci95,pValue:We.pValue,seed:Te.seed,verdict:Ee}}}let Oe;if(he?.cpu&&pe?.cpu){let be=new Map(he.cpu.totals.map((Te)=>[he.cpu.frames[Te.frameIx].key,Te])),Ce=new Map(pe.cpu.totals.map((Te)=>[pe.cpu.frames[Te.frameIx].key,Te])),ke=new Map(he.cpu.frames.map((Te)=>[Te.key,Te.name])),Re=new Map(pe.cpu.frames.map((Te)=>[Te.key,Te.name]));Oe=[...new Set([...be.keys(),...Ce.keys()])].map((Te)=>{let We=be.get(Te)?.selfUs??0,Ee=Ce.get(Te)?.selfUs??0;return{frameKey:Te,name:Re.get(Te)??ke.get(Te)??Te,baseSelfUs:We,candSelfUs:Ee,deltaPct:nn(We,Ee)}}).sort((Te,We)=>Math.abs(We.deltaPct)-Math.abs(Te.deltaPct));for(let Te of Oe)if((Te.baseSelfUs>=x.minFrameSelfUs||Te.candSelfUs>=x.minFrameSelfUs)&&Te.deltaPct>x.frameSelfPct)$e=!0}let Se;if(ge?.heap&&xe?.heap){let be=new Map(ge.heap.typeCounts.map((Re)=>[Re.type,Re])),Ce=new Map(xe.heap.typeCounts.map((Re)=>[Re.type,Re]));Se=[...new Set([...be.keys(),...Ce.keys()])].map((Re)=>{let ve=be.get(Re),Te=Ce.get(Re);return{type:Re,baseCount:ve?.count??0,candCount:Te?.count??0,baseBytes:ve?.retainedBytes,candBytes:Te?.retainedBytes,deltaPct:nn(ve?.count??0,Te?.count??0)}}).sort((Re,ve)=>Math.abs(ve.deltaPct)-Math.abs(Re.deltaPct));for(let Re of Se)if(Re.deltaPct>x.heapTypePct)$e=!0}return{id:e("cmp",ye,Pe),baselineMeasurementId:ye,candidateMeasurementId:Pe,timing:Ie,...Me.length>0&&{warnings:Me},frames:Oe,heapTypes:Se,thresholds:{...x,effectiveTimingPct:fe},verdict:$e?"fail":"pass"}}var qe="node_modules/.cache/ostia",lt=".ostia/baselines",dt={warmup:3,outDir:qe,baselineDir:lt,baseline:"main",thresholds:m,workloads:[]};class P extends Error{}var pt={runs:"samples"};function $n(u,R){for(let[x,C]of Object.entries(pt))if(x in u)throw new P(`${R}: "${x}" was renamed to "${C}".`);return{...dt,...u,thresholds:{...m,...u.thresholds??{}}}}async function kn(u){let R=Bun.file(u);if(!await R.exists())return;let x;try{x=await R.json()}catch(C){throw new P(`${u}: ${C instanceof Error?C.message:String(C)}`)}return $n(x,u)}async function Mn(u){let R=u.startsWith("/")?u:`${process.cwd()}/${u}`;if(!await Bun.file(R).exists())return;let x;try{x=await import(R)}catch(C){throw new P(`${u}: ${C instanceof Error?C.message:String(C)}`)}return $n(x.default??{},u)}async function E(u){if(u!==void 0)return u.endsWith(".ts")?Mn(u):kn(u);return await Mn("ostia.config.ts")??kn("ostia.config.json")}function o(u,R){return`${u.baselineDir}/${R??u.baseline}.json`}async function Y(){if(await Bun.file("ostia.config.ts").exists())return"ostia.config.ts";if(await Bun.file("ostia.config.json").exists())return"ostia.config.json";return}var ft=10,gt=3000000000,ht=3;function cn(u){if(u.timeSource)H(u.timeSource);let R=u.warmup??ht,x=u.samples,C=u.minSamples??ft,J=x??C,fe=x!==void 0?0:u.budgetMs!==void 0?u.budgetMs*1e6:gt,ie=u.timeSource!==void 0,ee=u.ignoreExitCodes??[],he=new Set(ee),pe=[],ge=0,xe=0,we=!1,ye;function Pe(){if(we)return!0;if(x!==void 0)return xe>=x;return xe>=J&&ge>=fe}async function $e(Me,Ie){if(u.prepare)await G(u.prepare,{phase:Me,index:Ie},{cwd:u.cwd,env:u.env,timeoutMs:u.timeoutMs,signal:u.signal});return re(u)}return{async warmup(){for(let Me=0;Me<R;Me++){if(u.signal?.aborted)return;await $e("warmup",Me)}},async step(){if(Pe()||u.signal?.aborted)return!1;let Me=await $e("timing",xe);if(u.signal?.aborted)return!1;if(Me.timeSourceNoMatch)ye??=Me.timeSourceMissOutput;if(pe.push({i:xe,wallNs:Me.wallNs,exitCode:Me.exitCode??void 0,userNs:Me.userNs,systemNs:Me.systemNs,maxRssBytes:Me.maxRssBytes,...Me.reportedNs!==void 0&&{reportedNs:Me.reportedNs},...Me.timedOut?{timedOut:!0}:{},...Me.timeSourceNoMatch?{timeSourceNoMatch:!0}:{}}),ge+=Me.wallNs,xe++,Me.exitCode!==null&&Me.exitCode!==0&&!he.has(Me.exitCode))we=!0;return!0},done:Pe,result(){let Me=pe.filter((ke)=>!ke.timedOut&&!ke.timeSourceNoMatch),Ie=Me.map((ke)=>ie?ke.reportedNs:ke.wallNs),Oe=[],Se=pe.filter((ke)=>ke.timedOut).length;if(Se>0)Oe.push({code:"timeout",message:`${Se} of ${pe.length} trial(s) timed out after ${u.timeoutMs}ms.`,data:{timeoutMs:u.timeoutMs,trials:Se}});let be=pe.filter((ke)=>ke.timeSourceNoMatch).length;if(be>0&&u.timeSource){let{pattern:ke}=u.timeSource;Oe.push({code:"time-source-no-match",message:`${be} of ${pe.length} trial(s) didn't match the timeSource pattern.`,data:{pattern:typeof ke==="string"?ke:ke.source,trials:be,...ye!==void 0&&{output:ye}}})}if(Ie.length===0)return{trials:pe,warnings:Oe};let Ce=f(Ie);return Oe.push(...j(Ce,Me.map((ke)=>ke.exitCode),ie?"reported":"subprocess",ee)),{trials:pe,timing:Ce,warnings:Oe}}}}async function un(u){await u.warmup();while(await u.step());}async function ne(u){let R=cn(u);return await un(R),R.result()}function B(u,R=[]){if(!u.timing)return!0;let x=new Set(R);return u.trials.some((C)=>C.exitCode!==void 0&&C.exitCode!==0&&!x.has(C.exitCode))}function tn(u,R){let x={samples:R.samples,minSamples:R.minSamples};for(let[C,J]of Object.entries(x))if(J!==void 0&&(!Number.isFinite(J)||J<1))throw RangeError(`${u}: ${C} must be >= 1, got ${J}`);if(R.budgetMs!==void 0&&!Number.isFinite(R.budgetMs))throw RangeError(`${u}: budgetMs must be finite, got ${R.budgetMs}`)}async function A(u,R){let x=new Set;for(let C of u)for await(let J of new Bun.Glob(C).scan({cwd:R,absolute:!1}))x.add(J);return[...x].sort()}var Rn=new URL("./runner.ts",import.meta.url).pathname;function Z(){return Math.max(1,navigator.hardwareConcurrency||1)}async function X(u,R){return A(u,R)}function bt(u){if(u===void 0)return;return u==="auto"?Z():u}async function W(u,R,x=process.cwd()){return{suites:u.suites.length>0?u.suites:R?.suites?await X(R.suites,x):[],budgetMs:u.budgetMs??R?.budgetMs,samples:u.samples??R?.samples,minSamples:u.minSamples??R?.minSamples,jobs:u.jobs??bt(R?.jobs),gc:u.gc??R?.gc??!1,cpu:u.cpu??R?.cpu??!1,alloc:u.alloc??R?.alloc??!1,filter:u.filter??R?.filter,isolate:u.isolate??R?.isolate??!1,preload:u.preload.length>0?u.preload:R?.preload??[],bunFlags:u.bunFlags.length>0?u.bunFlags:R?.bunFlags??[],outDir:u.outDir??R?.outDir,noiseCheck:u.noiseCheck,timeoutMs:u.timeoutMs??R?.timeoutMs,cwd:x}}async function v(u){tn("bench",u);let x=`${u.outDir??qe}/bench-tmp`,C=u.cwd??process.cwd(),J=Math.max(1,Math.floor(u.jobs??1)),fe={budgetMs:u.budgetMs,samples:u.samples,minSamples:u.minSamples,gc:u.gc,cpu:u.cpu,alloc:u.alloc,noiseCheck:!1},ie=u.noiseCheck===!1?void 0:l(),ee=ie?d(ie):void 0,he=(ye)=>ye.startsWith("/")?ye:`${C}/${ye}`,pe=u.suites.map(he),ge=(u.preload??[]).map(he),xe=u.bunFlags??[],we=async(ye,Pe)=>{let $e=new Set,Me=0,Ie,Oe=async()=>{while(Ie===void 0&&!u.signal?.aborted&&Me<ye.length){let Se=Me++;try{let be=V(u.timeoutMs,u.signal),Ce=Bun.spawn(ye[Se],{cwd:C,stdout:"inherit",stderr:"inherit",stdin:"ignore",...be.spawn});$e.add(Ce);let ke=await Ce.exited;if($e.delete(Ce),u.signal?.aborted)return;if(be.timedOut())throw Error(`Bench suite timed out after ${u.timeoutMs}ms: ${Pe(Se)}`);if(ke!==0)throw Error(`Bench suite failed: ${Pe(Se)} (runner exited ${ke})`)}catch(be){Ie??=be instanceof Error?be:Error(String(be));for(let Ce of $e)Ce.kill()}}};if(await Promise.all(Array.from({length:Math.min(J,ye.length)},Oe)),Ie)throw Ie};try{let ye=pe.map((ve)=>`${x}/${e("bench-plan",ve)}.json`),Pe=pe.map((ve)=>`${x}/${e("bench-primary",ve)}.json`),$e=pe.map((ve,Te)=>["bun",...xe,Rn,ve,Pe[Te],JSON.stringify({...fe,filter:u.filter,isolate:u.isolate,preload:ge,planPath:ye[Te]})]);await we($e,(ve)=>u.suites[ve]);let Me=await Promise.all(ye.map(async(ve)=>{if(!await Bun.file(ve).exists())return[];let{tasks:Te}=await Bun.file(ve).json();return Te})),Ie=await Promise.all(Pe.map(async(ve)=>await Bun.file(ve).exists()?s(ve):void 0)),Oe=[];for(let ve=0;ve<Me.length;ve++)for(let Te of Me[ve])if(Te.isolate)Oe.push({suiteIndex:ve,taskIds:[Te.id]});let Se=Oe.map((ve,Te)=>`${x}/${e("bench-item",pe[ve.suiteIndex],Te)}.json`),be=Oe.map((ve,Te)=>["bun",...xe,Rn,pe[ve.suiteIndex],Se[Te],JSON.stringify({...fe,taskIds:ve.taskIds,preload:ge,markIsolated:!0})]);await we(be,(ve)=>u.suites[Oe[ve].suiteIndex]);let Ce=await Promise.all(Se.map(async(ve)=>await Bun.file(ve).exists()?s(ve):void 0)),ke=[],Re=[];for(let ve=0;ve<Me.length;ve++){let Te=Ie[ve];if(!Te)continue;let We=new Map;for(let Be of Te.measurements){let De=We.get(Be.workloadId)??[];De.push(Be),We.set(Be.workloadId,De)}let Ee=0,Je=new Map;Oe.forEach((Be,De)=>{let Fe=Ce[De];if(Be.suiteIndex===ve&&Fe)Je.set(Be.taskIds[0],Fe)});for(let Be of Me[ve])if(Be.isolate){let De=Je.get(Be.id);if(!De)continue;let Fe=De.workloads[0];ke.push(Fe);for(let Ae of De.measurements)if(Ae.workloadId===Fe.id)Re.push(Ae)}else{let De=Te.workloads[Ee];ke.push(De),Ee++;for(let Fe of We.get(De.id)??[])Re.push(Fe)}}if(ee&&Re.length>0)Re[0].warnings=[...Re[0].warnings,ee];if(u.signal?.aborted&&Re.length>0){let ve=Re[Re.length-1];ve.warnings=[...ve.warnings,{code:"aborted",message:"Run was cancelled before it finished; this document holds whatever suites/tasks had already completed."}]}return r(ke,Re,ie)}finally{await Bun.spawn(["rm","-rf",x]).exited}}function ce(u,R,x=8){if(x<=1)throw RangeError(`range: multiplier must be > 1, got ${x}`);if(u<=0)throw RangeError(`range: start must be > 0, got ${u}`);let C=[];for(let J=u;J<=R;J*=x)C.push(J);if(!C.includes(R))C.push(R);return C}function je(u,R){if(R){let x=u.measurements.find((C)=>C.id===R);return x?.cpu?[x]:[]}return u.measurements.filter((x)=>x.phase==="cpu"&&x.cpu)}function He(u){let R=u.nodes,x=R.length,C=wt(u),J=new Int32Array(x).fill(-1);for(let he=0;he<x;he++)for(let pe of R[he].children){let ge=C(pe);if(ge!==-1)J[ge]=he}let fe=[];for(let he=0;he<x;he++)if(J[he]===-1)fe.push(he);let ie=[],ee=[];for(let he=fe.length-1;he>=0;he--)ee.push(fe[he]);while(ee.length>0){let he=ee.pop();ie.push(he);for(let pe of R[he].children){let ge=C(pe);if(ge!==-1&&J[ge]===he)ee.push(ge)}}return{count:x,indexOf:C,parentIx:J,roots:fe,order:ie}}function wt(u){let R=u.nodes,x=R.length,C=1/0,J=-1/0,fe=!0;for(let ee=0;ee<x;ee++){let he=R[ee].id;if(!Number.isInteger(he)){fe=!1;break}if(he<C)C=he;if(he>J)J=he}if(fe&&x>0&&J-C<x*4+64){let ee=J-C+1,he=new Int32Array(ee).fill(-1);for(let pe=0;pe<x;pe++)he[R[pe].id-C]=pe;return(pe)=>{let ge=pe-C;return ge>=0&&ge<ee?he[ge]:-1}}let ie=new Map;for(let ee=0;ee<x;ee++)ie.set(R[ee].id,ee);return(ee)=>ie.get(ee)??-1}function Cn(u,R){let{count:x,indexOf:C,parentIx:J,order:fe}=R,ie=new Float64Array(x),ee=new Float64Array(x),he=u.samples?.nodeIds??[],pe=u.samples?.timeDeltasUs??[];for(let xe=0;xe<he.length;xe++){let we=C(he[xe]);if(we===-1)continue;ie[we]+=pe[xe]??0,ee[we]+=1}let ge=new Float64Array(x);for(let xe=fe.length-1;xe>=0;xe--){let we=fe[xe];ge[we]+=ie[we];let ye=J[we];if(ye>=0)ge[ye]+=ge[we]}return{selfUs:ie,totalUs:ge,samples:ee}}var vn={name:"collapsed",async render(u,R={}){return{files:je(u,R.measurementId).map((J)=>{let fe=J.cpu,{nodes:ie,frames:ee}=fe,he=He(fe),pe=Array(he.count);for(let Pe of he.order){let $e=ee[ie[Pe].frameIx].name||"(anonymous)",Me=he.parentIx[Pe];pe[Pe]=Me===-1?$e:`${pe[Me]};${$e}`}let ge=new Float64Array(he.count),xe=[],we=fe.samples?.nodeIds??[];for(let Pe=0;Pe<we.length;Pe++){let $e=he.indexOf(we[Pe]);if($e===-1)continue;if(ge[$e]++===0)xe.push($e)}let ye=Array(xe.length);for(let Pe=0;Pe<xe.length;Pe++){let $e=xe[Pe];ye[Pe]=`${pe[$e]} ${ge[$e]}`}return{path:`${J.id}.collapsed.txt`,content:ye.join(`
|
|
3
3
|
`)+(ye.length>0?`
|
|
4
4
|
`:"")}})}}};var Tn={name:"cpuprofile",async render(u,R={}){let x=je(u,R.measurementId),C=[],J=[];for(let fe of x){if(fe.cpu?.origin!=="cpu-prof"&&fe.cpu?.origin!=="inspector"){J.push(`${fe.id} (origin ${fe.cpu?.origin??"unknown"} has no .cpuprofile artifact to pass through)`);continue}let ie=fe.artifacts.find((he)=>he.kind==="cpuprofile");if(!ie){J.push(`${fe.id} (no cpuprofile artifact recorded on this run)`);continue}let ee=Bun.file(ie.path);if(!await ee.exists()){J.push(`${fe.id} (artifact missing on disk: ${ie.path})`);continue}C.push({path:`${fe.id}.cpuprofile`,content:await ee.text()})}if(C.length===0&&J.length>0)return{text:`No .cpuprofile artifacts available:
|
|
5
5
|
${J.map((fe)=>` - ${fe}`).join(`
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
function f(o){if(o.length===0)throw Error("computeTimingStats: samples must be non-empty");let i=o.length,m=an(o),p=0;for(let P=0;P<i;P++)p+=o[P];let v=p/i,A=a(m,0.5),E=0;for(let P=0;P<i;P++){let K=o[P]-v;E+=K*K}let
|
|
3
|
-
${Ce(i,m)}`);let W=E[A];if(W===void 0)throw Error(`timeSource pattern ${v} matched${
|
|
2
|
+
function f(o){if(o.length===0)throw Error("computeTimingStats: samples must be non-empty");let i=o.length,m=an(o),p=0;for(let P=0;P<i;P++)p+=o[P];let v=p/i,A=a(m,0.5),E=0;for(let P=0;P<i;P++){let K=o[P]-v;E+=K*K}let F=Math.sqrt(E/i),W=m[0],Y=m[i-1],q=a(m,0.25),B=a(m,0.75),ue=B-q,Z=q-1.5*ue,de=B+1.5*ue,ce=q-3*ue,Q=B+3*ue,me=0,le=0;for(let P=0;P<i;P++){let K=o[P];if(K<ce||K>Q)le++;else if(K<Z||K>de)me++}let we=a(m,0.99),Te=new Float64Array(i);for(let P=0;P<i;P++)Te[P]=Math.abs(o[P]-A);Te.sort();let ye=a(Te,0.5);return{unit:"ns",samples:o,mean:v,median:A,stddev:F,min:W,max:Y,outliers:{mild:me,severe:le},p25:q,p75:B,p99:we,mad:ye}}function an(o){let i=new Float64Array(o.length);return i.set(o),i.sort(),i}function a(o,i){let m=o.length;if(m===1)return o[0];let p=i*(m-1),v=Math.floor(p),A=Math.ceil(p);if(v===A)return o[v];let E=p-v;return o[v]*(1-E)+o[A]*E}var un=5000000;function j(o,i,m="subprocess",p=[]){let v=[],A=o.samples[0];if(A!==void 0){let W=o.p75-o.p25;if(A>o.median+3*W&&A>2*o.median&&W>0)v.push({code:"slow-first-run",message:`First run took ${n(A)}, much slower than the median ${n(o.median)}. Consider more warmup.`,data:{firstNs:A,medianNs:o.median}})}if(m!=="inprocess"&&o.outliers.mild+o.outliers.severe>0)v.push({code:"outliers-detected",message:`${o.outliers.mild+o.outliers.severe} outlier(s) detected (${o.outliers.severe} severe, ${o.outliers.mild} mild).`,data:o.outliers});if(m==="subprocess"&&o.median<un)v.push({code:"fast-command",message:`Median run time (${(o.median/1e6).toFixed(3)}ms) is very fast; results may be dominated by spawn overhead.`,data:{medianNs:o.median}});let E=new Set(p),F=i.filter((W)=>W!==void 0&&W!==0&&!E.has(W));if(F.length>0)v.push({code:"nonzero-exit",message:`${F.length} of ${i.length} trial(s) exited non-zero.`,data:{exitCodes:F}});return v}var M=0.5,cn={ns:1,\u{b5}s:1000,ms:1e6,s:1e9};function S(o){let i=Math.abs(o);if(i>=1e9)return"s";if(i>=1e6)return"ms";if(i>=1000)return"\xB5s";return"ns"}function ln(o){let i=Math.floor(Math.log10(Math.max(Math.abs(o),1)))+1;return Math.max(1,3-i)}function n(o,i=S(o)){let m=o/cn[i];return`${m.toFixed(ln(m))} ${i}`}function U(o){return`${o.cpuModel} \xB7 ${o.cores} cores \xB7 load ${o.loadAvg1.toFixed(1)} \xB7 noise floor ${o.noise.floorPct.toFixed(1)}%`}function g(o){return`${o.sha} (${o.branch}${o.dirty?", dirty":""})`}function t(o){return o?.label??o?.command?.join(" ")??o?.entry?.task??o?.id??"unknown"}function L(o,i){if(o===1)return i?"1.00\xD7 (baseline)":"1.00\xD7";if(o>1)return`${o.toFixed(2)}\xD7 slower`;return`${(1/o).toFixed(2)}\xD7 faster`}function te(o){return o.replace(/\|/g,"\\|").replace(/</g,"<").replace(/>/g,">").replace(/`/g,"\\`").replace(/\r\n|\r|\n/g,"<br>")}function h(o){let i=o.trials.filter((p)=>!p.timedOut&&!p.timeSourceNoMatch&&p.userNs!==void 0&&p.systemNs!==void 0);if(i.length===0)return;let m=(p)=>a(Float64Array.from(p).sort(),0.5);return{userNs:m(i.map((p)=>p.userNs)),systemNs:m(i.map((p)=>p.systemNs))}}function _(o){return`${n(o.userNs)}/${n(o.systemNs)}`}class Ie extends Error{}function H(o){if(typeof o.pattern==="string")return;let{flags:i}=o.pattern;if(i.includes("g")||i.includes("y")||i.includes("d"))throw RangeError("timeSource pattern must not use the g or y flag")}function mn(...o){let i=o.filter((m)=>m!==void 0);if(i.length===0)return;if(i.length===1)return i[0];return AbortSignal.any(i)}var pn={ns:1,us:1000,ms:1e6,s:1e9};function V(o,i){let m=o!==void 0?AbortSignal.timeout(o):void 0,p=mn(m,i);return{spawn:p?{signal:p,killSignal:"SIGKILL"}:{},timedOut:()=>m?.aborted??!1}}async function re(o){let i=o.timeSource!==void 0,m=Bun.nanoseconds(),p=V(o.timeoutMs,o.signal),v=Bun.spawn(o.argv,{cwd:o.cwd,env:o.env,stdout:i?"pipe":"ignore",stderr:i?"pipe":"ignore",stdin:"ignore",...p.spawn}),A=i?Promise.all([new Response(v.stdout).text(),new Response(v.stderr).text()]):void 0,E=await v.exited,F=Bun.nanoseconds(),W=v.resourceUsage?.(),Y=p.timedOut(),q={wallNs:F-m,exitCode:Y?null:E,userNs:W?Number(W.cpuTime.user)*1000:void 0,systemNs:W?Number(W.cpuTime.system)*1000:void 0,maxRssBytes:W?.maxRSS,...Y?{timedOut:!0}:{}};if(A){let[B,ue]=await A;if(o.timeSource&&!Y)try{q.reportedNs=dn(o.timeSource,B,ue,o.argv)}catch(Z){if(!(Z instanceof Ie))throw Z;q.timeSourceNoMatch=!0,q.timeSourceMissOutput=fn(B,ue)}}return q}function dn(o,i,m,p=[]){let v=typeof o.pattern==="string"?new RegExp(o.pattern):o.pattern,A=o.group??1,E=v.exec(i)??v.exec(m),F=p.length>0?` for "${p.join(" ")}"`:"";if(!E)throw new Ie(`timeSource pattern ${v} did not match the output${F}. Output was:
|
|
3
|
+
${Ce(i,m)}`);let W=E[A];if(W===void 0)throw Error(`timeSource pattern ${v} matched${F} but has no capture group ${A} (matched text: "${E[0]}").`);let Y=Number(W);if(!Number.isFinite(Y))throw Error(`timeSource pattern ${v} group ${A} captured "${W}"${F}, which is not a number.`);return Y*pn[o.unit??"ms"]}function Ce(o,i){let p=(A)=>A.length>800?`${A.slice(0,800)}\u2026(${A.length-800} more)`:A,v=[];if(o.trim())v.push(`--- stdout ---
|
|
4
4
|
${p(o.trimEnd())}`);if(i.trim())v.push(`--- stderr ---
|
|
5
5
|
${p(i.trimEnd())}`);return v.length>0?v.join(`
|
|
6
6
|
`):"(empty)"}var Ne=2048;function fn(o,i){let m=Ce(o,i);if(Buffer.byteLength(m,"utf8")<=Ne)return m;let p=m.slice(0,Ne);while(Buffer.byteLength(p,"utf8")>Ne)p=p.slice(0,-1);return`${p}\u2026`}var gn=1048576,bn=(o)=>`
|
|
7
7
|
\u2026(${o} bytes elided)\u2026
|
|
8
|
-
`;async function hn(o,i=gn){let m=Math.floor(i/2),p=o.getReader(),v=[],A=0,E=[],
|
|
9
|
-
${W}`:""}`)}if(m.signal?.aborted)return;if(
|
|
10
|
-
${W}`:""}`)}}function Ae(o){if(o===void 0||typeof o==="function")return;return Array.isArray(o)?o:b(o)}function De(o){if(o===void 0)return;return{pattern:typeof o.pattern==="string"?o.pattern:o.pattern.source,...o.group!==void 0&&{group:o.group},...o.unit!==void 0&&{unit:o.unit}}}function b(o){return o.trim().split(/\s+/).filter(Boolean)}import{renameSync as
|
|
11
|
-
`}async function J(o,i){let m=`${i}.tmp-${process.pid}`;await Bun.write(m,o),
|
|
8
|
+
`;async function hn(o,i=gn){let m=Math.floor(i/2),p=o.getReader(),v=[],A=0,E=[],F=0,W=0;try{for(;;){let{done:Z,value:de}=await p.read();if(Z)break;if(!de||de.byteLength===0)continue;W+=de.byteLength;let ce=de;if(A<m){let Q=m-A;if(ce.byteLength<=Q){v.push(ce),A+=ce.byteLength;continue}v.push(ce.subarray(0,Q)),A+=Q,ce=ce.subarray(Q)}E.push(ce),F+=ce.byteLength;while(F>m&&E.length>0){let Q=E[0],me=F-m;if(Q.byteLength<=me)E.shift(),F-=Q.byteLength;else E[0]=Q.subarray(me),F-=me}}}finally{p.releaseLock()}let Y=new TextDecoder,q=Y.decode(Ue(v));if(W<=A+F)return q;let B=Y.decode(Ue(E)),ue=W-A-F;return`${q}${bn(ue)}${B}`}function Ue(o){let i=o.reduce((v,A)=>v+A.byteLength,0),m=new Uint8Array(i),p=0;for(let v of o)m.set(v,p),p+=v.byteLength;return m}async function G(o,i,m){if(typeof o==="function"){await o(i);return}let p=Ae(o),v=V(m.timeoutMs,m.signal),A=Bun.spawn(p,{cwd:m.cwd,env:m.env,stdout:"ignore",stderr:"pipe",stdin:"ignore",...v.spawn}),E=hn(A.stderr).catch(()=>""),F=await A.exited;if(v.timedOut()){let W=(await E).trim();throw Error(`prepare command "${p.join(" ")}" timed out after ${m.timeoutMs}ms before ${i.phase} trial ${i.index}.${W?`
|
|
9
|
+
${W}`:""}`)}if(m.signal?.aborted)return;if(F!==0){let W=(await E).trim();throw Error(`prepare command "${p.join(" ")}" exited with code ${F} before ${i.phase} trial ${i.index}.${W?`
|
|
10
|
+
${W}`:""}`)}}function Ae(o){if(o===void 0||typeof o==="function")return;return Array.isArray(o)?o:b(o)}function De(o){if(o===void 0)return;return{pattern:typeof o.pattern==="string"?o.pattern:o.pattern.source,...o.group!==void 0&&{group:o.group},...o.unit!==void 0&&{unit:o.unit}}}function b(o){return o.trim().split(/\s+/).filter(Boolean)}import{renameSync as yn}from"fs";import{isAbsolute as wn,relative as Tn}from"path";var Le={name:"ostia",version:"0.2.7",description:"Fast profiling and benchmarking for Bun.",type:"module",engines:{bun:">=1.4.0"},exports:{".":"./src/index.ts"},bin:{ostia:"src/cli/main.ts"},scripts:{build:"bun scripts/build.ts",test:"bun test",typecheck:"tsc6","typecheck:package":"tsc6 -p tests/types",lint:"biome check .","lint:fix":"biome check --write . --unsafe","lint:changed":"biome check --changed --no-errors-on-unmatched .","lint:fix:changed":"biome check --write --unsafe --changed --no-errors-on-unmatched .",knip:"knip-bun",bench:"bun src/cli/main.ts bench bench/*.ts","bench:baseline":"bun src/cli/main.ts bench bench/*.ts --budget 3000 --min-samples 30 --export-json .ostia/baselines/bench-main.json",baseline:"bun src/cli/main.ts baseline save",dogfood:"bun test && bun src/cli/main.ts ci",examples:"bun scripts/run-examples.ts"},devDependencies:{"@biomejs/biome":"2.5.14","@types/bun":"^1.4.2",knip:"^6.38.0",typescript:"npm:@typescript/typescript6@^6.0.2"},repository:{type:"git",url:"git+https://github.com/metonym/ostia.git"}};var R=Le.version;function T(o,i){return JSON.stringify(Pe(o),null,i)}function Pe(o){if(Array.isArray(o)){let i=!1;for(let m=0;m<o.length;m++){let p=o[m];if(p!==null&&typeof p==="object"){i=!0;break}}return i?o.map(Pe):o}if(o!==null&&typeof o==="object"){let i=o,m={};for(let p of Object.keys(i).sort())m[p]=Pe(i[p]);return m}return o}function e(o,...i){let m=Bun.CryptoHasher.hash("sha256",T(i),"hex");return`${o}_${m.slice(0,16)}`}var Re,_e=!1;function Oe(o){let i=Bun.spawnSync(["git",...o],{timeout:200,stdout:"pipe",stderr:"ignore"});return i.success?i.stdout.toString().trim():void 0}function We(){if(_e)return Re;_e=!0;try{let o=Oe(["rev-parse","--short","HEAD"]);if(o===void 0)Re=void 0;else{let i=Oe(["rev-parse","--abbrev-ref","HEAD"]),m=Oe(["status","--porcelain"]);Re={sha:o,branch:i??"HEAD",dirty:(m?.length??0)>0}}}catch{Re=void 0}return Re}function r(o,i,m){let p=We();return{schemaVersion:2,toolVersion:R,bunVersion:Bun.version,platform:{os:process.platform,arch:process.arch},createdAt:new Date().toISOString(),workloads:o,measurements:i,...m!==void 0&&{environment:m},...p!==void 0&&{git:p}}}function I(o,i,m={}){if(m.timeSource)H(m.timeSource);let p=Ae(m.prepare),v=De(m.timeSource),A=typeof m.prepare==="function"?m.prepare.toString():p;return{id:e("wl","subprocess",o,...A!==void 0||v!==void 0?[A??null,v??null]:[]),kind:"subprocess",command:o,label:i,...p!==void 0&&{prepare:p},...v!==void 0&&{timeSource:v}}}function se(o,i){return{id:e("wl","inprocess",o.name,o.toString()),kind:"inprocess",label:i}}function Ge(o,i,m={}){let p=wn(o)?Tn(process.cwd(),o):o;return{id:m.params!==void 0?e("wl","inprocess-entry",p,i,m.params):e("wl","inprocess-entry",p,i),kind:"inprocess",entry:{file:o,task:i,...m.group!==void 0&&{group:m.group}},...m.label!==void 0&&{label:m.label},...m.baseline!==void 0&&{baseline:m.baseline},...m.description!==void 0&&{description:m.description},...m.groupDescription!==void 0&&{groupDescription:m.groupDescription},...m.isolated!==void 0&&{isolated:m.isolated},...m.params!==void 0&&{params:m.params},...m.skipped!==void 0&&{skipped:m.skipped}}}function w(o){return{id:e("run",o.workload.id,"timing",o.configFingerprint,Bun.version,R),workloadId:o.workload.id,phase:"timing",instrumented:!1,configFingerprint:o.configFingerprint,trials:o.trials,timing:o.timing,warnings:o.warnings,artifacts:[],memory:xn(o.trials),...o.interleaved!==void 0&&{interleaved:o.interleaved}}}function xn(o){let i=o.map((m)=>m.maxRssBytes).filter((m)=>m!==void 0);if(i.length===0)return;return{origin:"resourceUsage",maxRssBytes:Math.max(...i)}}function y(o){return{id:e("run",o.workload.id,o.phase,o.configFingerprint,Bun.version,R),workloadId:o.workload.id,phase:o.phase,instrumented:!0,configFingerprint:o.configFingerprint,trials:[{i:0,wallNs:o.diagnosticWallNs,exitCode:o.exitCode}],diagnosticWallNs:o.diagnosticWallNs,cpu:o.cpu,heap:o.heap,memory:o.memory,jit:o.jit,warnings:o.warnings,artifacts:o.artifacts}}async function oe(o,i,m){let v=await Bun.file(m).arrayBuffer(),A=new Bun.CryptoHasher("sha256");return A.update(v),{id:e("art",o,i,m),kind:i,path:m,sha256:A.digest("hex"),bytes:v.byteLength}}function c(o){return e("cfg",o)}function k(o){return`${T(o,2)}
|
|
11
|
+
`}async function J(o,i){let m=`${i}.tmp-${process.pid}`;await Bun.write(m,o),yn(m,i)}async function u(o,i){await J(k(o),i)}class x extends Error{code;path;schemaVersion;constructor(o,i,m={}){super(i);this.name="OstiaDocumentError",this.code=o,this.path=m.path,this.schemaVersion=m.schemaVersion}}async function s(o){let i=await Bun.file(o).text(),m;try{m=JSON.parse(i)}catch(v){let A=v instanceof Error?v.message:String(v);throw new x("invalid-json",`${o}: invalid JSON (${A})`,{path:o})}let p=m!==null&&typeof m==="object"?m.schemaVersion:void 0;if(typeof p!=="number")throw new x("not-a-document",`${o}: not a ProfileDocument (missing schemaVersion)`,{path:o});if(p!==2)throw new x("unsupported-schema",`${o}: unsupported ProfileDocument schemaVersion ${p} (this ostia reads 2)`,{path:o,schemaVersion:p});return Sn(m)}function Sn(o){for(let i of o.measurements){let m=i.timing;if(!m||m.mad!==void 0||m.samples.length===0)continue;i.timing={...f(m.samples),...m.batch!==void 0&&{batch:m.batch}}}return o}import Ee from"os";var Mn=200,je=64,Rn=(()=>{let o=new Uint8Array(4096);for(let i=0;i<o.length;i++)o[i]=i*2654435761&255;return o})();function vn(o,i){let m=i;for(let p=0;p<o.length;p++)m^=o[p],m=Math.imul(m,16777619);return m>>>0}function Nn(o){let i=f(o);return{floorPct:i.median===0?0:i.mad/i.median*100,referenceMedianNs:i.median,samples:o.length}}function He(o=Mn){let i=o*1e6,m=[],p=0,v=Bun.nanoseconds(),A=0;while(A<i){let E=Bun.nanoseconds();for(let W=0;W<je;W++)p^=vn(Rn,W);let F=Bun.nanoseconds();m.push((F-E)/je),A=Bun.nanoseconds()-v}return Nn(m)}var In=0.75;function l(){let[o=0,i=0]=Ee.loadavg();return{cpuModel:Ee.cpus()[0]?.model??"unknown",cores:Ee.availableParallelism(),loadAvg1:o,loadAvg5:i,noise:He()}}function d(o){if(o.loadAvg1<=o.cores*In)return;return{code:"noisy-machine",message:`Load average ${o.loadAvg1.toFixed(2)} exceeds 75% of ${o.cores} available core(s); timing noise may be elevated.`,data:{loadAvg1:o.loadAvg1,cores:o.cores}}}import{profile as Pn}from"bun:jsc";var An=new Map([["LLInt","llint"],["Baseline","baseline"],["DFG","dfg"],["FTL","ftl"]]),Je=4294967295;function Ve(o,i){let m=i??o.interval*1e6,p=new Map,v=[];function A(P,K,X,be){let ne=p.get(P);if(ne===void 0)ne=new Map,p.set(P,ne);let he=K??"",xe=ne.get(he);if(xe===void 0)xe=v.length,ne.set(he,xe),v.push({key:e("fr",P,he),name:P,url:K,line:X,col:be});return xe}function E(P){let K=P.line===Je,X=K?void 0:P.line-1,be=K||P.column===Je?void 0:P.column-1;return A(P.name,P.sourceURL,X,be)}let F=A("(root)",void 0,void 0,void 0),W=1,Y={id:0,frameIx:F,children:new Map,selfUs:0,samples:0,totalUs:0},q=new Map([[0,Y]]),B={llint:0,baseline:0,dfg:0,ftl:0},ue=new Map,Z=[],de=[];for(let P of o.traces){let K=P.frames,X=Y;for(let he=K.length-1;he>=0;he--){let xe=E(K[he]),Se=X.children.get(xe);if(!Se)Se={id:W++,frameIx:xe,children:new Map,selfUs:0,samples:0,totalUs:0},X.children.set(xe,Se),q.set(Se.id,Se);X=Se}X.selfUs+=m,X.samples+=1,Z.push(X.id),de.push(m);let be=K[0],ne=be&&An.get(be.category);if(ne){B[ne]++;let he=ue.get(ne)??new Map;he.set(X.frameIx,(he.get(X.frameIx)??0)+1),ue.set(ne,he)}}function ce(P){let K=P.selfUs;for(let X of P.children.values())K+=ce(X);return P.totalUs=K,K}ce(Y);let Q=new Map;function me(P){let K=Q.get(P.frameIx);if(K)K.selfUs+=P.selfUs,K.totalUs+=P.totalUs,K.samples+=P.samples;else Q.set(P.frameIx,{frameIx:P.frameIx,selfUs:P.selfUs,totalUs:P.totalUs,samples:P.samples});for(let X of P.children.values())me(X)}me(Y);let le=[...q.values()].map((P)=>({id:P.id,frameIx:P.frameIx,children:[...P.children.values()].map((K)=>K.id)})),we={origin:"jsc-profile",samplingIntervalUs:m,frames:v,nodes:le,totals:[...Q.values()].sort((P,K)=>K.selfUs-P.selfUs),samples:{nodeIds:Z,timeDeltasUs:de}},Te=[...ue.entries()].flatMap(([P,K])=>[...K.entries()].sort((X,be)=>be[1]-X[1]).slice(0,3).map(([X,be])=>({tier:P,frameKey:v[X].key,samples:be})));return{cpu:we,jit:{origin:"jsc-profile",tiers:B,topFramesByTier:Te}}}var On=1000;async function z(o,i={}){let m=i.intervalUs??On,p,v=Bun.nanoseconds(),A=await Pn(async()=>(p=await o(),p),m),E=Bun.nanoseconds()-v,{cpu:F,jit:W}=Ve(A.stackTraces,m);return{result:p,cpu:F,jit:W,diagnosticWallNs:E}}var En=500,Bn=20,Ke=3,Fn=10,$n=2,Un=0.1,Cn=1000,qe=1e4,Dn=2*qe,Ln=1e6,_n=5,Ye=256;function Ze(o){let i=Math.log10(Math.max(1,o)/1e6),m=Math.round(Ke+$n*i);return Math.min(Fn,Math.max(Ke,m))}function Wn(o,i){let m=Math.floor(i/o);return Math.min(Bn,Math.max(m,Ze(o)))}var Gn;function pe(o){Gn=o}function ve(o){return o!==null&&typeof o==="object"&&typeof o.then==="function"}var jn=(async()=>{}).constructor,Hn=0;function Jn(o){let i=`/* ostia task loop ${Hn++} */
|
|
12
12
|
const t0 = Bun.nanoseconds()
|
|
13
13
|
for (let b = 0; b < n; b++) sink[b & ${Ye-1}] = ${o?"await ":""}fn()
|
|
14
|
-
return Bun.nanoseconds() - t0`;return(o?jn:Function)("fn","sink","n",i)}function ze(o,i){return Math.max(1,Math.ceil(Cn/o),Math.ceil(i/(o*qe)))}function Vn(o){let i=[...o].sort((m,p)=>m-p);return i[i.length>>1]}async function Xe(o,i={}){let m=(i.budgetMs??En)*1e6,p=m*(i.warmup??Un),v=Bun.nanoseconds(),A=o(),E=ve(A);if(E)await A;let
|
|
15
|
-
`);let A=zn(v,i);if(A.length===0)throw Error(`filter ${JSON.stringify(i)} matched zero of ${v.length} registered task(s) in ${m}.`);return A}import{heapStats as qn}from"bun:jsc";var Yn=100;function tn(){try{return qn().heapSize}catch{return process.memoryUsage().heapUsed}}async function rn(o,i=Yn){let m=Bun.nanoseconds();Bun.gc(!0);let p=tn();for(let E=0;E<i;E++){let
|
|
14
|
+
return Bun.nanoseconds() - t0`;return(o?jn:Function)("fn","sink","n",i)}function ze(o,i){return Math.max(1,Math.ceil(Cn/o),Math.ceil(i/(o*qe)))}function Vn(o){let i=[...o].sort((m,p)=>m-p);return i[i.length>>1]}async function Xe(o,i={}){let m=(i.budgetMs??En)*1e6,p=m*(i.warmup??Un),v=Bun.nanoseconds(),A=o(),E=ve(A);if(E)await A;let F=Math.max(1,Bun.nanoseconds()-v),W=Jn(E),Y=Array(Ye),q=(ne)=>W(o,Y,ne),B=Bun.nanoseconds(),ue=1;while(Bun.nanoseconds()-B<p){let ne=await q(ue);if(F=Math.max(1,ne/ue),ne<Ln)ue*=2}let Z=ze(F,m);if(Z>1){let ne=[];for(let he=0;he<_n;he++)ne.push(await q(Z)/Z);F=Math.max(1,Vn(ne)),Z=ze(F,m)}let de=F*Z,ce=i.samples??i.minSamples??Wn(de,m),Q=i.samples!==void 0?0:m,me=i.samples??Math.max(Dn,ce),le=[],we=Bun.nanoseconds(),Te=0,ye=0;while(ye<ce||Te<Q&&ye<me){let ne=await q(Z);if(le.push({i:ye,wallNs:ne/Z}),ye++,Te=Bun.nanoseconds()-we,i.gc)Bun.gc(!0);if(ye>=me&&ye>=ce)break}let P=le.map((ne)=>ne.wallNs),K=f(P);if(Z>1)K.batch=Z;let X=j(K,[],"inprocess"),be=Ze(de);if(le.length<be)X.push({code:"low-sample-count",message:`Only ${le.length} sample(s) at ~${Kn(de)} per trial; ${be} is the floor for this cost class. Raise minSamples or the time budget for a steadier number.`,data:{samples:le.length,target:be,trialCostNs:de}});return{trials:le,timing:K,warnings:X}}function Kn(o){if(o>=1e9)return`${(o/1e9).toFixed(2)}s`;if(o>=1e6)return`${(o/1e6).toFixed(1)}ms`;if(o>=1000)return`${(o/1000).toFixed(1)}\xB5s`;return`${o.toFixed(0)}ns`}var $e=[],ke,Me;function Be(o,i,m,p){let v=ke;ke={name:o,description:m?.description,isolate:m?.isolate,gc:m?.gc,cpu:m?.cpu,alloc:m?.alloc,before:m?.before,after:m?.after,skip:p.skip,only:p.only};try{i()}finally{ke=v}}var fe=Object.assign((o,i,m)=>Be(o,i,m,{}),{skip:(o,i,m)=>Be(o,i,m,{skip:!0}),only:(o,i,m)=>Be(o,i,m,{only:!0})});function Fe(o,i,m,p){let v=Me!==void 0||m?.params!==void 0?{...Me,...m?.params}:void 0;$e.push({groupName:ke?.name,groupDescription:ke?.description,groupIsolate:ke?.isolate,groupGc:ke?.gc,groupCpu:ke?.cpu,groupAlloc:ke?.alloc,groupBefore:ke?.before,groupAfter:ke?.after,name:o,fn:i,baseline:m?.baseline,params:v,skipped:p.skip||ke?.skip,only:p.only||ke?.only,opts:m})}var ge=Object.assign((o,i,m)=>Fe(o,i,m,{}),{skip:(o,i,m)=>Fe(o,i,m,{skip:!0}),only:(o,i,m)=>Fe(o,i,m,{only:!0})});function O(){return $e}function ie(){$e.length=0,ke=void 0,Me=void 0}function ae(o,i){let m=Me;Me=o;try{return i()}finally{Me=m}}function C(o){return o.groupName?`${o.groupName}/${o.name}`:o.name}function ee(o,i){return o.opts?.isolate??o.groupIsolate??i}function Qe(o,i){return o.opts?.gc??o.groupGc??i}function en(o,i){return o.opts?.cpu??o.groupCpu??i}function nn(o,i){return o.opts?.alloc??o.groupAlloc??i}function zn(o,i){if(!i)return[...o];let m=new RegExp(i);return o.filter((p)=>m.test(C(p)))}function D(o,i,m){let p=o.filter((E)=>E.only),v=p.length>0?p:o;if(p.length>0)process.stderr.write(`bench: ${p.length} task(s) selected by .only
|
|
15
|
+
`);let A=zn(v,i);if(A.length===0)throw Error(`filter ${JSON.stringify(i)} matched zero of ${v.length} registered task(s) in ${m}.`);return A}import{heapStats as qn}from"bun:jsc";var Yn=100;function tn(){try{return qn().heapSize}catch{return process.memoryUsage().heapUsed}}async function rn(o,i=Yn){let m=Bun.nanoseconds();Bun.gc(!0);let p=tn();for(let E=0;E<i;E++){let F=o();if(ve(F))await F}Bun.gc(!0);let v=tn(),A=Bun.nanoseconds()-m;return{memory:{origin:"heapStats",bytesPerOp:Math.max(0,(v-p)/i)},diagnosticWallNs:A}}var Zn=200,Xn=20;async function on(o,i=Zn){let m=i*1e6,p=async()=>{let F=Bun.nanoseconds();while(Bun.nanoseconds()-F<m){let W=o();if(ve(W))await W}},{cpu:v,jit:A,diagnosticWallNs:E}=await z(p);return{cpu:v,jit:A,diagnosticWallNs:E}}function sn(o){let{llint:i,baseline:m,dfg:p,ftl:v}=o.tiers,A=i+m+p+v;if(A===0)return;let E=i/A*100,F=m/A*100,W=p/A*100,Y=v/A*100;if(E+F<=Xn)return;return{code:"jit-cold",message:`${(E+F).toFixed(1)}% of CPU samples were in the llint/baseline tiers: the JIT never warmed this task up.`,data:{llintPct:E,baselinePct:F,dfgPct:W,ftlPct:Y}}}async function N(o,i,m){let v=i.some((q)=>!q.skipped)&&m.noiseCheck!==!1?l():void 0,A=v?d(v):void 0,E=new Map,F=new Map;i.forEach((q,B)=>{if(q.groupName===void 0||q.skipped)return;if(!E.has(q.groupName))E.set(q.groupName,B);F.set(q.groupName,B)});let W=[],Y=[];for(let q=0;q<i.length;q++){let B=i[q],ue=C(B),Z=Ge(o,ue,{label:ue,baseline:B.baseline,group:B.groupName,description:B.opts?.description,groupDescription:B.groupDescription,isolated:m.markIsolated,params:B.params,skipped:B.skipped});if(W.push(Z),B.skipped)continue;let de=B.groupName!==void 0&&E.get(B.groupName)===q,ce=B.groupName!==void 0&&F.get(B.groupName)===q;if(de&&B.groupBefore)await B.groupBefore();if(B.opts?.before)await B.opts.before();let Q={budgetMs:B.opts?.budgetMs??m.budgetMs,samples:B.opts?.samples??m.samples,minSamples:B.opts?.minSamples??m.minSamples,warmup:m.warmup,gc:Qe(B,m.gc??!1)},me=await Xe(B.fn,Q);if(Y.push(w({workload:Z,configFingerprint:c({budgetMs:Q.budgetMs??null,samples:Q.samples??null,minSamples:Q.minSamples??null,gc:Q.gc??!1}),trials:me.trials,timing:me.timing,warnings:A&&Y.length===0?[...me.warnings,A]:me.warnings})),en(B,m.cpu??!1)){let le=await on(B.fn),we=sn(le.jit);Y.push(y({workload:Z,phase:"cpu",configFingerprint:c({cpu:!0}),diagnosticWallNs:le.diagnosticWallNs,cpu:le.cpu,jit:le.jit,warnings:we?[we]:[],artifacts:[]}))}if(nn(B,m.alloc??!1)){let le=await rn(B.fn);Y.push(y({workload:Z,phase:"memstats",configFingerprint:c({alloc:!0}),diagnosticWallNs:le.diagnosticWallNs,memory:le.memory,warnings:[],artifacts:[]}))}if(B.opts?.after)await B.opts.after();if(ce&&B.groupAfter)await B.groupAfter()}return r(W,Y,v)}
|
|
16
16
|
export{T,e,M,S,n,U,g,t,L,te,h,_,f,a,j,H,V,re,G,b,R,r,I,se,w,y,oe,c,k,J,u,x,s,l,d,z,pe,fe,ge,O,ie,ae,C,ee,D,N};
|
package/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{e,g,t,b,R,r,I,w,c,k,J,u,x,s,l,d}from"./chunk-
|
|
3
|
+
import{e,g,t,b,R,r,I,w,c,k,J,u,x,s,l,d}from"./chunk-n02qf2mf.js";import{m,q,K,F,P,E,o,Y,A,ne,B,Z,X,W,v,p,i,Q}from"./chunk-5qtsmr3p.js";import{resolve as Be}from"path";function be(a){return e("cache",a.workloadId,a.phase,a.configFingerprint,a.bunVersion,a.toolVersion,a.instrumented,a.inputsDigest??null)}async function we(a,n=process.cwd()){if(a.length===0)return;let f=await A(a,n),h=await Promise.all(f.map(async(y)=>{let C=await Bun.file(Be(n,y)).arrayBuffer();return{path:y,sha256:Bun.CryptoHasher.hash("sha256",C,"hex")}}));return e("inputs",h)}function ke(a,n){return`${a}/cache/${n}.json`}async function ve(a,n){let f=Bun.file(ke(a,n));if(!await f.exists())return;return await f.json()}async function ye(a,n,f){await Bun.write(ke(a,n),`${JSON.stringify(f,null,2)}
|
|
4
4
|
`)}var Ce=600000;class ce extends Error{path;constructor(a){super(`No baseline document at ${a}. Create one with: ostia baseline save ${a.split("/").pop().replace(/\.json$/,"")}`);this.path=a}}class ue extends Error{path;missing;total;constructor(a,n,f){super(`${n} of ${f} configured workload(s) have no matching row in baseline ${a} (by workload id). Re-seed with: ostia baseline save`);this.path=a;this.missing=n;this.total=f}}function _e(a,n,f){if(a)return a;return n===f?"fail":"warn"}async function pe(a,n){let f=a.noiseCheck===!1?void 0:l(),h=f?d(f):void 0,y=[];for(let C of a.workloads){if(C.suites){let _=await X(C.suites,process.cwd()),te=await W({suites:_,preload:[],bunFlags:[],noiseCheck:!1},a.bench),ee=await v({...te,outDir:te.outDir??a.outDir,timeoutMs:te.timeoutMs??Ce});for(let z of ee.workloads){let j=ee.measurements.find((oe)=>oe.workloadId===z.id&&oe.phase==="timing");if(!j)continue;if(h)j.warnings.push(h);y.push({workload:z,status:"executed",run:j,harnessFailed:!1})}continue}let D=I(C.command,C.label,{prepare:C.prepare,timeSource:C.timeSource}),M=await we(C.inputs??[]),S=c({samples:a.samples??null,budgetMs:a.budgetMs??null,minSamples:a.minSamples??null,warmup:a.warmup}),G=C.inputs!==void 0&&typeof C.prepare!=="function",L=be({workloadId:D.id,phase:"timing",configFingerprint:S,bunVersion:Bun.version,toolVersion:R,instrumented:!1,inputsDigest:M}),U=n||!G?void 0:await ve(a.outDir,L),O,T;if(U)O=U,T="cached";else{let _=await ne({argv:C.command,samples:a.samples,budgetMs:a.budgetMs,minSamples:a.minSamples,warmup:a.warmup,prepare:C.prepare,timeSource:C.timeSource,timeoutMs:C.timeoutMs??Ce,ignoreExitCodes:C.ignoreExitCodes});if(O=w({workload:D,configFingerprint:S,trials:_.trials,timing:_.timing,warnings:h?[..._.warnings,h]:_.warnings}),G)await ye(a.outDir,L,O);T="executed"}y.push({workload:D,status:T,run:O,harnessFailed:B(O,C.ignoreExitCodes)})}return{results:y,environment:f}}async function xe(a){let{config:n}=a,f=o(n,a.baselineName);if(!await Bun.file(f).exists())throw new ce(f);let y=await s(f),{results:C,environment:D}=await pe(n,a.full),M=C.map((j)=>({...j})),S=M.filter((j)=>j.status==="executed").length,G=M.length-S,L=M.filter((j)=>j.harnessFailed).length,U=r(M.map((j)=>j.workload),M.map((j)=>j.run),D),O=0,T=0,_=0,te=q(y,U,n.thresholds);for(let j of M){let oe=te.compare(j.workload.id);if(!oe){_++;continue}if(j.comparison=oe,oe.verdict==="pass")O++;else T++}if(_>0){if(_e(n.onMissingBaseline,_,M.length)==="fail")throw new ue(f,_,M.length)}let ee=M.map((j)=>j.comparison).filter((j)=>j!==void 0);U.comparisons=ee;let z=te.unmatched();return U.unmatched={baseOnly:z.baseOnly.map((j)=>j.id),candOnly:z.candOnly.map((j)=>j.id)},U.comparisonSummary=K(ee,te.effectiveTimingPct),{document:U,summary:{total:M.length,cached:G,executed:S,passed:O,regressed:T,missingBaseline:_,failed:L,results:M,unmatched:z},baseline:y}}function Pe(a){let n=[];if(n.push(`${a.total} workloads`),n.push(`${a.cached} cached`),n.push(`${a.executed} executed`),a.missingBaseline>0)n.push(`${a.missingBaseline} skipped (no matching baseline workload)`);if(a.failed>0){let h=a.results.filter((y)=>y.harnessFailed).map((y)=>t(y.workload));n.push(`${a.failed} failed (harness error, a command exited non-zero or produced no samples: ${h.join(", ")})`)}let f=a.results.filter((h)=>h.comparison?.verdict==="fail").map((h)=>{let y=h.comparison.timing,C=t(h.workload);return y?`${y.medianDeltaPct>0?"+":""}${y.medianDeltaPct.toFixed(1)}% median on ${C}`:C});return n.push(`${a.passed} passed ${a.regressed} regressed${f.length>0?` (${f.join(", ")})`:""}`),n.push(""),n.push(`Profile CI: ${a.regressed>0||a.failed>0?"\u2717":"\u2713"}`),`${n.join(`
|
|
5
5
|
`)}
|
|
6
6
|
`}async function $e(a,n){let{results:f,environment:h}=await pe(a,!1),y=r(f.map((D)=>D.workload),f.map((D)=>D.run),h),C=o(a,n);return await u(y,C),C}async function Me(a){let n=[];try{let h=new Bun.Glob("*.json");for await(let y of h.scan({cwd:a.baselineDir,absolute:!1}))n.push(y.replace(/\.json$/,""))}catch{return[]}return n.sort(),(await Promise.all(n.map(async(h)=>{let y=o(a,h);try{let C=await s(y);return{name:h,path:y,createdAt:C.createdAt,toolVersion:C.toolVersion,bunVersion:C.bunVersion,workloads:C.workloads.length,...C.git!==void 0&&{git:C.git}}}catch{return}}))).filter((h)=>h!==void 0)}function ae(a){return a instanceof Error?a.message:String(a)}var H=(a)=>Bun.write(Bun.stdout,a),Se=(a)=>Bun.write(Bun.stderr,a);class se extends Error{}var Fe=[],Ae=new Set(["minimal","json","jsonl"]);async function We(a){let{isatty:n}=await import("tty");if(!n(2))return!0;return a.some((f,h)=>f==="--format"&&Ae.has(a[h+1]??"")||f.startsWith("--format=")&&Ae.has(f.slice(9)))}async function N(a,n,f){if(await Se(n.endsWith(`
|
package/index.d.ts
CHANGED
|
@@ -611,8 +611,6 @@ interface InprocessTimingOptions {
|
|
|
611
611
|
|
|
612
612
|
export declare function keep(value: unknown): void;
|
|
613
613
|
|
|
614
|
-
type TaskFn = () => unknown | Promise<unknown>;
|
|
615
|
-
|
|
616
614
|
interface BenchOptions {
|
|
617
615
|
suites: string[];
|
|
618
616
|
/** Wall-clock sampling budget per task, ms (default 500). */
|
|
@@ -779,6 +777,19 @@ interface GroupFn {
|
|
|
779
777
|
|
|
780
778
|
export declare const group: GroupFn;
|
|
781
779
|
|
|
780
|
+
interface TaskFn {
|
|
781
|
+
(name: string, fn: () => unknown | Promise<unknown>, opts?: TaskOptions): void;
|
|
782
|
+
/** Registers the task as skipped: the runner never measures it, but the
|
|
783
|
+
* document still carries its workload (marked `Workload.skipped`) so a
|
|
784
|
+
* renderer or `compare` can say so explicitly instead of the task simply
|
|
785
|
+
* being absent. */
|
|
786
|
+
skip: (name: string, fn: () => unknown | Promise<unknown>, opts?: TaskOptions) => void;
|
|
787
|
+
/** When any task or group in the suite uses `.only`, the runner restricts
|
|
788
|
+
* the whole suite file to only those tasks (before `--filter` narrows
|
|
789
|
+
* further) and prints a one-line notice to stderr. */
|
|
790
|
+
only: (name: string, fn: () => unknown | Promise<unknown>, opts?: TaskOptions) => void;
|
|
791
|
+
}
|
|
792
|
+
|
|
782
793
|
export declare const task: TaskFn;
|
|
783
794
|
|
|
784
795
|
export interface RunOptions extends MeasureTasksOpts {
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{m,F,v,ce,p,i,ue,me,le,Q,de}from"./chunk-
|
|
2
|
+
import{m,F,v,ce,p,i,ue,me,le,Q,de}from"./chunk-5qtsmr3p.js";import{r,u,x,s,pe,fe,ge}from"./chunk-n02qf2mf.js";export{m as DEFAULT_THRESHOLDS,p as MINIMAL_PROTOCOL_VERSION,x as OstiaDocumentError,v as bench,F as compareDocuments,r as createDocument,le as defineConfig,fe as group,pe as keep,s as loadDocument,de as profile,ce as range,i as renderers,ue as run,u as saveDocument,me as sweep,ge as task,Q as time};
|
package/package.json
CHANGED
package/runner.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{u,O,ie,C,ee,D,N}from"./chunk-
|
|
3
|
+
import{u,O,ie,C,ee,D,N}from"./chunk-n02qf2mf.js";async function c(){let[t,a,o]=process.argv.slice(2);if(!t||!a)return process.stderr.write(`bench runner: usage: runner.ts <suiteFile> <outputPath> [optsJson]
|
|
4
4
|
`),2;let e=o?JSON.parse(o):{};for(let s of e.preload??[])await import(s);ie(),await import(t);let i=O();if(i.length===0)return process.stderr.write(`bench runner: ${t} registered no tasks (no task() calls found).
|
|
5
5
|
`),2;let r;try{r=D(i,e.filter,t)}catch(s){return process.stderr.write(`bench runner: ${s.message}
|
|
6
6
|
`),2}if(e.taskIds){let s=new Set(e.taskIds);r=r.filter((n)=>s.has(C(n)))}if(e.planPath){let s=r.map((n)=>({id:C(n),isolate:ee(n,e.isolate??!1)}));await Bun.write(e.planPath,JSON.stringify({tasks:s}))}let p=e.taskIds?r:r.filter((s)=>!ee(s,e.isolate??!1)),l=await N(t,p,e);return await u(l,a),0}c().then((t)=>process.exit(t));
|