1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

perf(cache): compile ts to js in parallel for deno cache (#23892)

Closes https://github.com/denoland/deno/issues/23860
This commit is contained in:
David Sherret 2024-05-20 13:49:12 -04:00 committed by GitHub
parent eb97f110db
commit c89f9f9ad1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,9 @@ use crate::cache::ParsedSourceCache;
use deno_ast::SourceMapOption; use deno_ast::SourceMapOption;
use deno_ast::TranspileResult; use deno_ast::TranspileResult;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::futures::stream::FuturesUnordered;
use deno_core::futures::FutureExt;
use deno_core::futures::StreamExt;
use deno_core::ModuleCodeString; use deno_core::ModuleCodeString;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_graph::MediaType; use deno_graph::MediaType;
@ -48,9 +51,12 @@ impl Emitter {
&self, &self,
graph: &ModuleGraph, graph: &ModuleGraph,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
// todo(dsherret): we could do this concurrently let mut futures = FuturesUnordered::new();
for module in graph.modules() { for module in graph.modules() {
if let Module::Js(module) = module { let Module::Js(module) = module else {
continue;
};
let is_emittable = matches!( let is_emittable = matches!(
module.media_type, module.media_type,
MediaType::TypeScript MediaType::TypeScript
@ -60,16 +66,22 @@ impl Emitter {
| MediaType::Tsx | MediaType::Tsx
); );
if is_emittable { if is_emittable {
futures.push(
self self
.emit_parsed_source( .emit_parsed_source(
&module.specifier, &module.specifier,
module.media_type, module.media_type,
&module.source, &module.source,
) )
.await?; .boxed_local(),
);
} }
} }
while let Some(result) = futures.next().await {
result?; // surface errors
} }
Ok(()) Ok(())
} }