Skip to content

perf: reduce stack mem-move #1739

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions crates/rspack_core/src/ast/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl fmt::Debug for Context {

#[derive(Debug, Clone)]
pub struct Ast {
root: SwcStylesheet,
root: Box<SwcStylesheet>,
context: Arc<Context>,
}

Expand All @@ -34,7 +34,7 @@ impl Hash for Ast {
impl Ast {
pub fn new(root: SwcStylesheet, source_map: Arc<SourceMap>) -> Self {
Self {
root,
root: box root,
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI box keyword / box pattern is perma-unstable rust-lang/rust#49733 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intended to place the item in the box to the heap directly. There are some places that used this, if the syntax changes, I will update this.

context: Arc::new(Context::new(source_map)),
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_core/src/ast/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use swc_core::ecma::visit::{
/// Use this to avoid using `use swc_ecma_visit::*`
/// and save changes in self
#[derive(Debug, Clone, Hash)]
pub struct Program(SwcProgram);
pub struct Program(Box<SwcProgram>);

impl Program {
pub fn fold_with<V: ?Sized + Fold>(&mut self, v: &mut V) {
let p = std::mem::replace(&mut self.0, SwcProgram::Module(Module::dummy()));
let p = std::mem::replace(&mut self.0, box SwcProgram::Module(Module::dummy()));
self.0 = p.fold_with(v);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ impl Ast {
SwcProgram::Script(_) => false,
};
Self {
program: Program(program),
program: Program(box program),
context: Arc::new(Context::new(is_esm, source_map)),
}
}
Expand Down