summaryrefslogtreecommitdiff
path: root/cli/ops/compiler.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2019-10-03 21:23:29 +1000
committerRyan Dahl <ry@tinyclouds.org>2019-10-03 07:23:29 -0400
commitd9ff4eccb50d87da9338333c90e3082bebd065c8 (patch)
tree0dc9227bfe874bb4ddca4f687ee0dec4b20a61a1 /cli/ops/compiler.rs
parentc878a14365efc299b52ee49d4f5e06553f6cb41c (diff)
Async compiler processing (#3043)
Basically this does pre-processing of TypeScript files and gathers all the dependencies asynchronously. Only then after all the dependencies are gathered, does it do a compile, which at that point all the dependencies are cached in memory in the compiler, so with the exception of the hard coded assets, there are no ops during the compilation. Because op_fetch_source_files is now handled asynchronously in the runtime, we can eliminate the tokio_util::block_on() which was causing the increase in threads. Benchmarking on my machine has shown about a 5% improvement in speed when dealing with compiling TypeScript. Still a long way to go, but an improvement. In theory the module name resolution and the fetching of the source files could be broken out as two different ops. This would prevent situations of sending the full source file all the time when actually the module is the same module referenced by multiple modules, but that could be done subsequently to this.
Diffstat (limited to 'cli/ops/compiler.rs')
-rw-r--r--cli/ops/compiler.rs39
1 files changed, 21 insertions, 18 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs
index 2dd7422df..8fb1ad988 100644
--- a/cli/ops/compiler.rs
+++ b/cli/ops/compiler.rs
@@ -1,7 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
+use crate::futures::future::join_all;
+use crate::futures::Future;
use crate::state::ThreadSafeState;
-use crate::tokio_util;
use deno::*;
#[derive(Deserialize)]
@@ -40,7 +41,7 @@ struct FetchSourceFilesArgs {
pub fn op_fetch_source_files(
state: &ThreadSafeState,
args: Value,
- _zero_copy: Option<PinnedBuf>,
+ _data: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
let args: FetchSourceFilesArgs = serde_json::from_value(args)?;
@@ -58,23 +59,25 @@ pub fn op_fetch_source_files(
futures.push(fut);
}
- // WARNING: Here we use tokio_util::block_on() which starts a new Tokio
- // runtime for executing the future. This is so we don't inadvertently run
- // out of threads in the main runtime.
- let files = tokio_util::block_on(futures::future::join_all(futures))?;
- let res: Vec<serde_json::value::Value> = files
- .into_iter()
- .map(|file| {
- json!({
- "moduleName": file.url.to_string(),
- "filename": file.filename.to_str().unwrap(),
- "mediaType": file.media_type as i32,
- "sourceCode": String::from_utf8(file.source_code).unwrap(),
- })
- })
- .collect();
+ let future = join_all(futures)
+ .map_err(ErrBox::from)
+ .and_then(move |files| {
+ let res = files
+ .into_iter()
+ .map(|file| {
+ json!({
+ "url": file.url.to_string(),
+ "filename": file.filename.to_str().unwrap(),
+ "mediaType": file.media_type as i32,
+ "sourceCode": String::from_utf8(file.source_code).unwrap(),
+ })
+ })
+ .collect();
+
+ futures::future::ok(res)
+ });
- Ok(JsonOp::Sync(json!(res)))
+ Ok(JsonOp::Async(Box::new(future)))
}
#[derive(Deserialize)]