Skip to content

Commit

Permalink
perf: spawn runtime task ASAP (#276)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing! -->

### Description

<!-- Please insert your description here and provide especially info about the "what" this PR is solving -->

### Test Plan

<!-- e.g. is there anything you'd like reviewers to focus on? -->

---
  • Loading branch information
hyf0 committed Nov 15, 2023
1 parent 4a8f245 commit ba7f558
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions crates/rolldown/src/bundler/stages/scan_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ impl<Fs: FileSystem + Default + 'static> ScanStage<Fs> {
Self { input_options, plugin_driver, fs, resolver }
}

pub async fn scan(&self) -> BatchedResult<ScanStageOutput> {
assert!(!self.input_options.input.is_empty(), "You must supply options.input to rolldown");

let mut module_loader = ModuleLoader::new(
Arc::clone(&self.input_options),
Arc::clone(&self.plugin_driver),
self.fs.share(),
Arc::clone(&self.resolver),
);

module_loader.try_spawn_runtime_module_task();

let resolved_entries = self.resolve_entries()?;

let mut runtime = Runtime::new(module_loader.try_spawn_runtime_module_task());

let (modules, symbols, entries) =
module_loader.fetch_all_modules(&resolved_entries, &mut runtime).await?;

Ok(ScanStageOutput { modules, entries, symbols, runtime })
}

fn resolve_entries(&self) -> BatchedResult<Vec<(Option<String>, ResolvedRequestInfo)>> {
let resolver = &self.resolver;
let plugin_driver = &self.plugin_driver;
Expand Down Expand Up @@ -89,24 +111,4 @@ impl<Fs: FileSystem + Default + 'static> ScanStage<Fs> {
Err(errors)
}
}

pub async fn scan(&self) -> BatchedResult<ScanStageOutput> {
assert!(!self.input_options.input.is_empty(), "You must supply options.input to rolldown");

let mut module_loader = ModuleLoader::new(
Arc::clone(&self.input_options),
Arc::clone(&self.plugin_driver),
self.fs.share(),
Arc::clone(&self.resolver),
);

let resolved_entries = self.resolve_entries()?;

let mut runtime = Runtime::new(module_loader.try_spawn_runtime_module_task());

let (modules, symbols, entries) =
module_loader.fetch_all_modules(&resolved_entries, &mut runtime).await?;

Ok(ScanStageOutput { modules, entries, symbols, runtime })
}
}

0 comments on commit ba7f558

Please sign in to comment.