Skip to content
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

perf: spawn jsr futures on executor #395

Merged
merged 4 commits into from
Feb 21, 2024

Conversation

littledivy
Copy link
Member

@littledivy littledivy commented Feb 21, 2024

Adds an abstract trait for executing futures onto an async runtime.

A default Tokio spawn executor is included behing the tokio_executor feature flag.

Closes #394

lib/lib.rs Outdated
&self,
future: futures::future::LocalBoxFuture<'static, ()>,
) -> futures::future::LocalBoxFuture<'static, ()> {
// TODO(littledivy): bug in wasm_bindgen where Shared futures panic on spawn.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@littledivy
Copy link
Member Author

I can't test the perf in Deno because it is a few deno_graph versions behind it seems. Are there any other benchmarks I can run? @dsherret

@dsherret
Copy link
Member

dsherret commented Feb 21, 2024

@littledivy it's up-to-date. Pull the latest main.

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for looking into this!

fn execute(&self, fut: BoxedFuture) -> BoxedFuture;
}

impl<'a> Default for &'a dyn Executor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I did not know it was possible to do this for traits.

lib/lib.rs Outdated Show resolved Hide resolved
@littledivy
Copy link
Member Author

littledivy commented Feb 21, 2024

2.5x faster on incremental and half peak memory usage:

divy@divy:~/gh/denoland/jsr_benchmarks$ poop 'deno cache --no-check --no-config /home/divy/gh/denoland/jsr_benchmarks/dax_std/mod_jsr.ts' '/home/divy/gh/littledivy/deno/target/release/deno cache --no-check --no-config /home/divy/gh/denoland/jsr_benchmarks/dax_std/mod_jsr.ts'
Benchmark 1 (20 runs): deno cache --no-check --no-config /home/divy/gh/denoland/jsr_benchmarks/dax_std/mod_jsr.ts
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           254ms ±  333ms     177ms … 1.67s           1 ( 5%)        0%
  peak_rss           62.9MB ± 1.38MB    62.1MB … 68.6MB          1 ( 5%)        0%
  cpu_cycles          652M  ±  169M      606M  … 1.37G           1 ( 5%)        0%
  instructions       1.01G  ±  239M      961M  … 2.03G           1 ( 5%)        0%
  cache_references   45.0M  ± 11.4M     42.0M  … 93.5M           1 ( 5%)        0%
  cache_misses       9.77M  ± 4.34M     8.61M  … 28.2M           1 ( 5%)        0%
  branch_misses      3.44M  ± 1.35M     3.09M  … 9.18M           1 ( 5%)        0%
Benchmark 2 (50 runs): /home/divy/gh/littledivy/deno/target/release/deno cache --no-check --no-config /home/divy/gh/denoland/jsr_benchmarks/dax_std/mod_jsr.ts
  measurement          mean ± σ            min … max           outliers         delta
  wall_time           100ms ±  217ms    68.1ms … 1.61s           2 ( 4%)        ⚡- 60.5% ± 53.2%
  peak_rss           39.9MB ± 4.06MB    39.0MB … 68.0MB          1 ( 2%)        ⚡- 36.5% ±  3.0%
  cpu_cycles          200M  ±  136M      177M  … 1.14G           1 ( 2%)        ⚡- 69.4% ± 11.8%
  instructions        310M  ±  208M      281M  … 1.75G           1 ( 2%)        ⚡- 69.4% ± 11.3%
  cache_references   11.9M  ± 9.13M     10.5M  … 75.2M           2 ( 4%)        ⚡- 73.5% ± 11.6%
  cache_misses       3.77M  ± 2.85M     3.25M  … 23.5M           1 ( 2%)        ⚡- 61.4% ± 18.1%
  branch_misses      1.02M  ± 1.05M      844K  … 8.27M           1 ( 2%)        ⚡- 70.4% ± 17.5%

5+ seconds faster with no cache (network is involved):

time /home/divy/gh/littledivy/deno/target/release/deno cache --no-check --no-config -r /home/divy/gh/denoland/jsr_benchmarks/dax_std/mod_jsr.ts

real	0m15.635s
user	0m0.067s
sys	0m0.034s
time deno cache --no-check --no-config -r /home/divy/gh/denoland/jsr_benchmarks/dax_std/mod_jsr.ts

real	0m20.879s
user	0m0.301s
sys	0m0.188s

lib/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@dsherret dsherret merged commit fad142c into denoland:main Feb 21, 2024
4 checks passed
@littledivy littledivy deleted the perf_jsr_Tasks branch February 22, 2024 02:52
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.

Optimize futures for JSR package loading
2 participants