Skip to content

Conversation

nathanwhit
Copy link
Member

@nathanwhit nathanwhit commented Dec 9, 2024

moves promise resolution and tracking from js to rust, curious to see if we could gain any perf from moving eventLoopTick to rust.

right now we have the rust event loop calling into JS to actually dispatch most of the event loop (which also often involves calling op_run_microtasks from JS, which calls back into rust!)

we might be able to skip a hop and eliminate op_run_microtasks entirely


so far the perf impact on the promise resolution is roughly neutral (as expected). it might take moving the whole thing to rust to see a real impact (if any)

bench:

import { barrierAwait, barrierCreate } from "checkin:async";

const count = 1e6;
barrierCreate("barrier", count);
const promises = [];
for (let i = 0; i < count; i++) {
  promises.push(barrierAwait("barrier"));
}
await Promise.all(promises);
❯ hyperfine "./target/release/dcore test.ts" "./dcore-base test.ts"
Benchmark 1: ./target/release/dcore test.ts
  Time (mean ± σ):      1.344 s ±  0.015 s    [User: 1.457 s, System: 0.352 s]
  Range (min … max):    1.329 s …  1.380 s    10 runs
 
Benchmark 2: ./dcore-base test.ts
  Time (mean ± σ):      1.337 s ±  0.019 s    [User: 2.299 s, System: 0.499 s]
  Range (min … max):    1.305 s …  1.367 s    10 runs
 
Summary
  ./dcore-base test.ts ran
    1.00 ± 0.02 times faster than ./target/release/dcore test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant