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

reduce memory usage in analyser #8061

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/turbopack-ecmascript/src/analyzer/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ impl Analyzer<'_> {
self.add_value(id, value);
}

#[inline]
sokra marked this conversation as resolved.
Show resolved Hide resolved
sokra marked this conversation as resolved.
Show resolved Hide resolved
fn add_effect(&mut self, effect: Effect) {
self.effects.push(effect);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/turbopack-ecmascript/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
/// A constant primitive value.
Constant(ConstantValue),
/// An constant URL object.
Url(Url),
Url(Box<Url>),
/// Some kind of well-known object
/// (must not be an array, otherwise Array.concat needs to be changed)
WellKnownObject(WellKnownObjectKind),
Expand Down Expand Up @@ -3681,7 +3681,7 @@
let start = Instant::now();
async fn handle_args(
args: Vec<EffectArg>,
queue: &mut Vec<(usize, Effect)>,
queue: &mut Vec<(usize, Box<Effect>)>,
sokra marked this conversation as resolved.
Show resolved Hide resolved
var_graph: &VarGraph,
i: usize,
) -> Vec<JsValue> {
Expand All @@ -3694,7 +3694,7 @@
EffectArg::Closure(v, effects) => {
new_args.push(resolve(var_graph, v).await);
queue.extend(
effects.effects.into_iter().rev().map(|e| (i, e)),

Check failure on line 3697 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on ubuntu

expected `{closure@mod.rs:3697:83}` to be a closure that returns `(usize, Box<Effect>)`, but it returns `(usize, Effect)`

Check failure on line 3697 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on macos

expected `{closure@mod.rs:3697:83}` to be a closure that returns `(usize, Box<Effect>)`, but it returns `(usize, Effect)`

Check failure on line 3697 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on windows

expected `{closure@mod.rs:3697:83}` to be a closure that returns `(usize, Box<Effect>)`, but it returns `(usize, Effect)`
);
}
EffectArg::Spread => {
Expand All @@ -3704,7 +3704,7 @@
}
new_args
}
match effect {
match *effect {

Check failure on line 3707 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on ubuntu

type `Effect` cannot be dereferenced

Check failure on line 3707 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on macos

type `Effect` cannot be dereferenced

Check failure on line 3707 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on windows

type `Effect` cannot be dereferenced
sokra marked this conversation as resolved.
Show resolved Hide resolved
Effect::Conditional {
condition, kind, ..
} => {
Expand Down Expand Up @@ -3733,7 +3733,7 @@
}
Effect::Call { func, args, .. } => {
let func = resolve(&var_graph, func).await;
let new_args = handle_args(args, &mut queue, &var_graph, i).await;

Check failure on line 3736 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on ubuntu

mismatched types

Check failure on line 3736 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on macos

mismatched types

Check failure on line 3736 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on windows

mismatched types
resolved.push((
format!("{parent} -> {i} call"),
JsValue::call(Box::new(func), new_args),
Expand All @@ -3747,7 +3747,7 @@
} => {
let obj = resolve(&var_graph, obj).await;
let prop = resolve(&var_graph, prop).await;
let new_args = handle_args(args, &mut queue, &var_graph, i).await;

Check failure on line 3750 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on ubuntu

mismatched types

Check failure on line 3750 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on macos

mismatched types

Check failure on line 3750 in crates/turbopack-ecmascript/src/analyzer/mod.rs

View workflow job for this annotation

GitHub Actions / Turbopack Rust testing on windows

mismatched types
resolved.push((
format!("{parent} -> {i} member call"),
JsValue::member_call(Box::new(obj), Box::new(prop), new_args),
Expand Down
1 change: 1 addition & 0 deletions crates/turbopack-ecmascript/src/analyzer/well_known.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ pub fn path_to_file_url(args: Vec<JsValue>) -> JsValue {
if args.len() == 1 {
if let Some(path) = args[0].as_str() {
Url::from_file_path(path)
.map(Box::new)
.map(JsValue::Url)
.unwrap_or_else(|_| {
JsValue::unknown(
Expand Down
3 changes: 2 additions & 1 deletion crates/turbopack-ecmascript/src/references/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,8 @@ pub(crate) async fn analyse_ecmascript_module_internal(
// of an effect we might want to add more effects into the middle of the
// processing. Using a stack where effects are appended in reverse
// order allows us to do that. It's recursion implemented as Stack.
let mut queue_stack = Mutex::new(Vec::new());
let mut queue_stack: parking_lot::lock_api::Mutex<parking_lot::RawMutex, Vec<Action>> =
Mutex::new(Vec::new());
sokra marked this conversation as resolved.
Show resolved Hide resolved
queue_stack
.get_mut()
.extend(effects.into_iter().map(Action::Effect).rev());
Expand Down
Loading