mirror of
https://github.com/swc-project/swc.git
synced 2024-11-27 04:47:03 +03:00
perf(es/codegen): Reduce usage of tracing::instrument
(#9604)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/9603
This commit is contained in:
parent
8b8599776a
commit
2f06fc559c
6
.changeset/funny-drinks-remain.md
Normal file
6
.changeset/funny-drinks-remain.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
swc_core: patch
|
||||
swc_ecma_codegen: patch
|
||||
---
|
||||
|
||||
perf(es/codegen): Reduce usage of `tracing::instrument`
|
@ -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)?;
|
||||
|
||||
@ -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)?;
|
||||
|
||||
@ -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)?;
|
||||
|
||||
@ -644,7 +646,7 @@ where
|
||||
}
|
||||
|
||||
#[emitter]
|
||||
#[tracing::instrument(skip_all)]
|
||||
|
||||
fn emit_str_lit(&mut self, node: &Str) -> Result {
|
||||
self.wr.commit_pending_semi()?;
|
||||
|
||||
@ -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)?;
|
||||
}
|
||||
@ -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),
|
||||
@ -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),
|
||||
@ -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)?;
|
||||
|
||||
@ -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)?;
|
||||
|
||||
@ -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)?;
|
||||
}
|
||||
@ -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)?;
|
||||
|
||||
|
@ -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)?;
|
||||
@ -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 {
|
||||
|
@ -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 {
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
@ -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 {
|
||||
@ -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());
|
||||
@ -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());
|
||||
@ -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 {
|
||||
@ -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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user