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

feat: parallelize downloads from TS compiler #2949

Merged
merged 5 commits into from
Sep 14, 2019

Conversation

bartlomieju
Copy link
Member

Fixes #2626

A small change to the compiler that requests all imports from a file at once instead of doing N round trips. Still needs a bit of cleanup.

master

$ time deno -r fetch https://deno.land/std/testing/runner.ts
Download https://deno.land/std/testing/runner.ts
Compile https://deno.land/std/testing/runner.ts
Download https://deno.land/std/flags/mod.ts
Download https://deno.land/std/fs/mod.ts
Download https://deno.land/std/testing/mod.ts
Download https://deno.land/std/fs/empty_dir.ts
Download https://deno.land/std/fs/ensure_dir.ts
Download https://deno.land/std/fs/ensure_file.ts
Download https://deno.land/std/fs/ensure_link.ts
Download https://deno.land/std/fs/ensure_symlink.ts
Download https://deno.land/std/fs/exists.ts
Download https://deno.land/std/fs/glob.ts
Download https://deno.land/std/fs/globrex.ts
Download https://deno.land/std/fs/move.ts
Download https://deno.land/std/fs/copy.ts
Download https://deno.land/std/fs/read_file_str.ts
Download https://deno.land/std/fs/write_file_str.ts
Download https://deno.land/std/fs/read_json.ts
Download https://deno.land/std/fs/write_json.ts
Download https://deno.land/std/fs/walk.ts
Download https://deno.land/std/fs/eol.ts
Download https://deno.land/std/fs/utils.ts
Download https://deno.land/std/fs/path/mod.ts
Download https://deno.land/std/fs/path/win32.ts
Download https://deno.land/std/fs/path/posix.ts
Download https://deno.land/std/fs/path/constants.ts
Download https://deno.land/std/fs/path/interface.ts
Download https://deno.land/std/fs/path/utils.ts
Download https://deno.land/std/testing/asserts.ts
Download https://deno.land/std/fmt/colors.ts
Download https://deno.land/std/testing/diff.ts
Download https://deno.land/std/testing/format.ts

real	0m4.273s
user	0m2.615s
sys	0m0.310s

this PR

$ time target/release/deno -r fetch https://deno.land/std/testing/runner.ts
Download https://deno.land/std/testing/runner.ts
Compile https://deno.land/std/testing/runner.ts
Download https://deno.land/std/flags/mod.ts
Download https://deno.land/std/fs/mod.ts
Download https://deno.land/std/testing/mod.ts
Download https://deno.land/std/fs/empty_dir.ts
Download https://deno.land/std/fs/ensure_dir.ts
Download https://deno.land/std/fs/ensure_file.ts
Download https://deno.land/std/fs/ensure_link.ts
Download https://deno.land/std/fs/ensure_symlink.ts
Download https://deno.land/std/fs/exists.ts
Download https://deno.land/std/fs/glob.ts
Download https://deno.land/std/fs/globrex.ts
Download https://deno.land/std/fs/move.ts
Download https://deno.land/std/fs/copy.ts
Download https://deno.land/std/fs/read_file_str.ts
Download https://deno.land/std/fs/write_file_str.ts
Download https://deno.land/std/fs/read_json.ts
Download https://deno.land/std/fs/write_json.ts
Download https://deno.land/std/fs/walk.ts
Download https://deno.land/std/fs/eol.ts
Download https://deno.land/std/fs/utils.ts
Download https://deno.land/std/fs/path/mod.ts
Download https://deno.land/std/fs/path/win32.ts
Download https://deno.land/std/fs/path/posix.ts
Download https://deno.land/std/fs/path/constants.ts
Download https://deno.land/std/fs/path/interface.ts
Download https://deno.land/std/fs/path/utils.ts
Download https://deno.land/std/testing/asserts.ts
Download https://deno.land/std/fmt/colors.ts
Download https://deno.land/std/testing/diff.ts
Download https://deno.land/std/testing/format.ts

real	0m2.259s
user	0m2.494s
sys	0m0.250s

CC @ry @kitsonk

@bartlomieju bartlomieju force-pushed the feat-parallelize_ts_downloads branch from 1d5e968 to 01c246e Compare September 14, 2019 12:26
@bartlomieju
Copy link
Member Author

I must admit, doing this PR with JSON ops is a breeze... I couldn't figure it out with Flatbufs a couple times.

"mediaType": out.media_type as i32,
"sourceCode": String::from_utf8(out.source_code).unwrap(),
})))
let files = tokio_util::block_on(futures::future::join_all(futures))?;
Copy link
Member

Choose a reason for hiding this comment

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

👍 elegant

(at some point we need to get rid of this block_on stuff tho...)

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - no comments

@ry ry merged commit 686b86e into denoland:master Sep 14, 2019
@bartlomieju bartlomieju deleted the feat-parallelize_ts_downloads branch September 14, 2019 16:11
@ry
Copy link
Member

ry commented Sep 15, 2019

This caused the thread count to jump from 11 to 77 threads in cold_relative_import:

Screen Shot 2019-09-15 at 10 38 43 AM

This is due to parallel usage of block_on... :(

@bartlomieju
Copy link
Member Author

This is bad news. We really need to figure out what to do with block_on. Wouldn't small increase of default number of threads solve this issue?

@ry
Copy link
Member

ry commented Sep 15, 2019

@bartlomieju The issue is that we're starting a whole new tokio runtime for each module resolved - it is wildly inefficient.

Wouldn't small increase of default number of threads solve this issue?

No

@ry
Copy link
Member

ry commented Sep 16, 2019

@bartlomieju After some thought, I will not revert your patch. Your patch speeds up an important (unfortunately unmeasured) benchmark. I think what you're doing is more or less correct and just exposing a lower-level problem. I've added #2960 to 1.0 blockers to solve this most important design problem.

@bartlomieju
Copy link
Member Author

@bartlomieju After some thought, I will not revert your patch. Your patch speeds up an important (unfortunately unmeasured) benchmark. I think what you're doing is more or less correct and just exposing a lower-level problem. I've added #2960 to 1.0 blockers to solve this most important design problem.

@ry alright, I will investigate alternate solutions as well

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.

TS compiler loads modules synchronously
2 participants