Repository navigation
bench: backport main's benchmarks to release for before/after runs #6103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8f0f1b7
bench: backport main's benchmarks to release for before/after runs
kixelated 49e0295
Merge remote-tracking branch 'origin/release' into backport/benchmarks
kixelated 465fb4a
fix(bench): drop moq-stats' unused criterion and run the tracked effect
kixelated d2487c8
fix(bench): test the effect row's result as a promise, not for truthi…
kixelated 23b4e75
fix(bench): keep kio's contended bench beside its other bench targets
kixelated File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** Sweep snapshot codec cost over document size and changed keys. */ | ||
| import { Decoder } from "../src/snapshot/decoder.ts"; | ||
| import { Encoder } from "../src/snapshot/encoder.ts"; | ||
|
|
||
| const updates = 256; | ||
| console.log("keys\tchanged\tcompression\tms/update"); | ||
| for (const keys of [1, 10, 100, 1000]) { | ||
| for (const changed of new Set([1, Math.min(10, keys)])) { | ||
| for (const compression of ["none", "deflate"] as const) { | ||
| const samples: number[] = []; | ||
| for (let sample = 0; sample < 3; sample++) { | ||
| const config = { deltaRatio: 100, compression }; | ||
| const encoder = new Encoder<Record<string, number>>(config); | ||
| const decoder = new Decoder<Record<string, number>>(config); | ||
| let value = Object.fromEntries(Array.from({ length: keys }, (_, n) => [`k${n}`, 0])); | ||
| const start = performance.now(); | ||
| for (let n = 1; n <= updates; n++) { | ||
| value = { ...value }; | ||
| for (let key = 0; key < changed; key++) value[`k${key}`] = n; | ||
| const frame = encoder.update(value); | ||
| if (frame) { | ||
| if (frame.keyframe) decoder.snapshot(frame.payload); | ||
| else decoder.delta(frame.payload); | ||
| frame.commit(); | ||
| } | ||
| if (decoder.decode()?.k0 !== n) throw new Error("codec benchmark lost an update"); | ||
| } | ||
| samples.push((performance.now() - start) / updates); | ||
| } | ||
| samples.sort((a, b) => a - b); | ||
| console.log(`${keys}\t${changed}\t${compression}\t${samples[1]?.toFixed(6)}`); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** Time creating and closing an Effect, bare and with a tracked signal, against a bare `new Error()`. */ | ||
| import { Effect, Signal } from "../src/index.ts"; | ||
|
|
||
| const runs = 20_000; | ||
| const reps = 9; | ||
| const signal = new Signal(0); | ||
| let checksum = 0; | ||
| let tracked = 0; | ||
|
|
||
| const ops: [string, () => void | Promise<void>][] = [ | ||
| // The creation stack each Effect captures for its diagnostics; the floor for the rows below. | ||
| [ | ||
| "new-error", | ||
| () => { | ||
| checksum += new Error("created here:").message.length; | ||
| }, | ||
| ], | ||
| [ | ||
| "create-close", | ||
| () => { | ||
| new Effect().close(); | ||
| checksum++; | ||
| }, | ||
| ], | ||
| [ | ||
| "create-get-close", | ||
| async () => { | ||
| const effect = new Effect((effect) => { | ||
| tracked += effect.get(signal) + 1; | ||
| }); | ||
| // The callback runs in a microtask, so yield once to let it track the signal before closing. | ||
| await Promise.resolve(); | ||
| effect.close(); | ||
| }, | ||
| ], | ||
| ]; | ||
|
|
||
| // Nanoseconds per op for the fastest of several reps, since a slower one measured the machine. | ||
| async function time(body: () => void | Promise<void>): Promise<number> { | ||
| let best = Number.POSITIVE_INFINITY; | ||
| for (let rep = 0; rep < reps; rep++) { | ||
| const start = performance.now(); | ||
| for (let i = 0; i < runs; i++) { | ||
| // Awaiting a sync row would add a microtask hop it doesn't pay. | ||
| const pending = body(); | ||
| if (pending instanceof Promise) await pending; | ||
| } | ||
| best = Math.min(best, ((performance.now() - start) * 1e6) / runs); | ||
| } | ||
| return best; | ||
| } | ||
|
|
||
| // Time every op once first and discard it, so the JIT has seen all of them and the first row isn't timing warmup. | ||
| for (const [, body] of ops) await time(body); | ||
|
|
||
| console.log("op,ns_per_op"); | ||
| for (const [op, body] of ops) console.log(`${op},${(await time(body)).toFixed(0)}`); | ||
| if (checksum === 0) throw new Error("benchmark did no work"); | ||
| if (tracked === 0) throw new Error("create-get-close never ran its effect"); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effectschedules its callback in a microtask, but this closes the instance synchronously, so every scheduled run observes the closed state and returns without executingeffect.get(signal). Consequently, thecreate-get-closerow measures scheduling and immediate closure rather than creating and closing an effect with a tracked signal, while the queued callbacks drain outside the timed section and the checksum from the other rows masks the omission.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid: the callback never ran, so the row timed scheduling plus an immediate close. Fixed in 465fb4a: the row yields once so the effect tracks the signal before
close(), the timing loop awaits only rows that return a promise (the sync rows pay no extra hop), and a separatetrackedcounter fails the run if the effect never executes. main'sjs/signals/bench/effect.tshas the same bug and needs the same fix for the before/after rows to pair.(Written by Claude Opus 5.5)