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

perf(es/codegen): Reduce usage of tracing::instrument #9604

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 11 additions & 9 deletions crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]
pub fn emit_module(&mut self, node: &Module) -> Result {
self.emit_leading_comments_of_span(node.span(), false)?;

Expand All @@ -180,6 +181,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]
pub fn emit_script(&mut self, node: &Script) -> Result {
self.emit_leading_comments_of_span(node.span(), false)?;

Expand Down Expand Up @@ -609,7 +611,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_lit(&mut self, node: &Lit) -> Result {
self.emit_leading_comments_of_span(node.span(), false)?;

Expand Down Expand Up @@ -644,7 +646,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_str_lit(&mut self, node: &Str) -> Result {
self.wr.commit_pending_semi()?;

Expand Down Expand Up @@ -689,7 +691,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_num_lit(&mut self, num: &Number) -> Result {
self.emit_num_lit_internal(num, false)?;
}
Expand Down Expand Up @@ -888,7 +890,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_expr(&mut self, node: &Expr) -> Result {
match node {
Expr::Array(ref n) => emit!(n),
Expand Down Expand Up @@ -1404,7 +1406,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_class_member(&mut self, node: &ClassMember) -> Result {
match *node {
ClassMember::Constructor(ref n) => emit!(n),
Expand Down Expand Up @@ -1780,7 +1782,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_class_constructor(&mut self, n: &Constructor) -> Result {
self.emit_leading_comments_of_span(n.span(), false)?;

Expand Down Expand Up @@ -3040,7 +3042,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_expr_stmt(&mut self, e: &ExprStmt) -> Result {
self.emit_leading_comments_of_span(e.span, false)?;

Expand All @@ -3050,7 +3052,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_block_stmt(&mut self, node: &BlockStmt) -> Result {
self.emit_block_stmt_inner(node, false)?;
}
Expand Down Expand Up @@ -3475,7 +3477,7 @@ where
}

#[emitter]
#[tracing::instrument(skip_all)]

fn emit_try_stmt(&mut self, n: &TryStmt) -> Result {
self.emit_leading_comments_of_span(n.span(), false)?;

Expand Down
18 changes: 0 additions & 18 deletions crates/swc_ecma_codegen/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ macro_rules! semi {
/// - `srcmap!(false)` for end (span.hi)
macro_rules! srcmap {
($emitter:expr, $n:expr, true) => {{
#[cfg(debug_assertions)]
let _span = tracing::span!(
tracing::Level::ERROR,
"srcmap",
file = file!(),
line = line!()
)
.entered();

let lo = $n.span_lo();
if !lo.is_dummy() {
$emitter.wr.add_srcmap(lo)?;
Expand All @@ -125,15 +116,6 @@ macro_rules! srcmap {
srcmap!($emitter, $n, false, false)
};
($emitter:expr, $n:expr, false, $subtract:expr) => {
#[cfg(debug_assertions)]
let _span = tracing::span!(
tracing::Level::ERROR,
"srcmap",
file = file!(),
line = line!()
)
.entered();

let hi = $n.span_hi();
if !hi.is_dummy() {
if $subtract {
Expand Down
37 changes: 16 additions & 21 deletions crates/swc_ecma_codegen/src/text_writer/basic_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,13 @@ impl<'a, W: Write> JsWriter<'a, W> {

#[inline]
fn raw_write(&mut self, data: &str) -> Result {
// #[cfg(debug_assertions)]
// tracing::trace!("Write: `{}`", data);
self.wr.write_all(data.as_bytes())?;

Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write(&mut self, span: Option<Span>, data: &str) -> Result {
if !data.is_empty() {
if self.line_start {
Expand Down Expand Up @@ -138,9 +136,6 @@ impl<'a, W: Write> JsWriter<'a, W> {
col: self.line_pos as _,
};

// #[cfg(debug_assertions)]
// tracing::trace!("SourceMap: {:?} => {:?}", byte_pos, loc);

srcmap.push((byte_pos, loc));
}
}
Expand All @@ -167,42 +162,42 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> {
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_space(&mut self) -> Result {
self.write(None, " ")?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_keyword(&mut self, span: Option<Span>, s: &'static str) -> Result {
self.write(span, s)?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_operator(&mut self, span: Option<Span>, s: &str) -> Result {
self.write(span, s)?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_param(&mut self, s: &str) -> Result {
self.write(None, s)?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_property(&mut self, s: &str) -> Result {
self.write(None, s)?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_line(&mut self) -> Result {
let pending = self.pending_srcmap.take();
if !self.line_start {
Expand All @@ -222,7 +217,7 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> {
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_lit(&mut self, span: Span, s: &str) -> Result {
if !s.is_empty() {
self.srcmap(span.lo());
Expand All @@ -234,14 +229,14 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> {
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_comment(&mut self, s: &str) -> Result {
self.write(None, s)?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_str_lit(&mut self, span: Span, s: &str) -> Result {
if !s.is_empty() {
self.srcmap(span.lo());
Expand All @@ -253,34 +248,34 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> {
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_str(&mut self, s: &str) -> Result {
self.write(None, s)?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_symbol(&mut self, span: Span, s: &str) -> Result {
self.write(Some(span), s)?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn write_punct(&mut self, span: Option<Span>, s: &'static str) -> Result {
self.write(span, s)?;
Ok(())
}

#[inline]
#[tracing::instrument(skip_all)]

fn care_about_srcmap(&self) -> bool {
self.srcmap.is_some()
}

#[inline]
#[tracing::instrument(skip_all)]

fn add_srcmap(&mut self, pos: BytePos) -> Result {
if self.srcmap.is_some() {
if self.line_start {
Expand All @@ -293,7 +288,7 @@ impl<'a, W: Write> WriteJs for JsWriter<'a, W> {
}

#[inline]
#[tracing::instrument(skip_all)]

fn commit_pending_semi(&mut self) -> Result {
Ok(())
}
Expand Down
Loading