Remove tracing from cheap functions

Turns out that having tracing enabled on some functions that get called a lot distorts the traces so that their parent stack frames look much more expensive than they actually are.
This commit is contained in:
Laurenz 2023-05-11 11:35:45 +02:00
parent 2f0b5eeae0
commit 998a3c44fd
6 changed files with 5 additions and 21 deletions

View File

@ -290,7 +290,6 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
} }
/// Determines the columns sizes and then layouts the grid row-by-row. /// Determines the columns sizes and then layouts the grid row-by-row.
#[tracing::instrument(name = "grid layout", skip(self))]
pub fn layout(mut self) -> SourceResult<GridLayout> { pub fn layout(mut self) -> SourceResult<GridLayout> {
self.measure_columns()?; self.measure_columns()?;
@ -318,6 +317,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
} }
/// Determine all column sizes. /// Determine all column sizes.
#[tracing::instrument(name = "GridLayouter::measure_columns", skip_all)]
fn measure_columns(&mut self) -> SourceResult<()> { fn measure_columns(&mut self) -> SourceResult<()> {
// Sum of sizes of resolved relative tracks. // Sum of sizes of resolved relative tracks.
let mut rel = Abs::zero(); let mut rel = Abs::zero();

View File

@ -116,6 +116,7 @@ pub trait Layout {
/// ///
/// This element must be layouted again in the same order for the results to /// This element must be layouted again in the same order for the results to
/// be valid. /// be valid.
#[tracing::instrument(name = "Layout::measure", skip_all)]
fn measure( fn measure(
&self, &self,
vt: &mut Vt, vt: &mut Vt,
@ -198,6 +199,7 @@ fn realize_root<'a>(
} }
/// Realize into an element that is capable of block-level layout. /// Realize into an element that is capable of block-level layout.
#[tracing::instrument(skip_all)]
fn realize_block<'a>( fn realize_block<'a>(
vt: &mut Vt, vt: &mut Vt,
scratch: &'a Scratch<'a>, scratch: &'a Scratch<'a>,
@ -261,7 +263,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
} }
} }
#[tracing::instrument(skip_all)]
fn accept( fn accept(
&mut self, &mut self,
mut content: &'a Content, mut content: &'a Content,
@ -327,7 +328,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
} }
} }
#[tracing::instrument(skip_all)]
fn styled( fn styled(
&mut self, &mut self,
elem: &'a Content, elem: &'a Content,
@ -342,7 +342,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Ok(()) Ok(())
} }
#[tracing::instrument(skip(self, local, outer))]
fn interrupt_style( fn interrupt_style(
&mut self, &mut self,
local: &Styles, local: &Styles,
@ -377,7 +376,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Ok(()) Ok(())
} }
#[tracing::instrument(skip(self))]
fn interrupt_list(&mut self) -> SourceResult<()> { fn interrupt_list(&mut self) -> SourceResult<()> {
if !self.list.items.is_empty() { if !self.list.items.is_empty() {
let staged = mem::take(&mut self.list.staged); let staged = mem::take(&mut self.list.staged);
@ -391,7 +389,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Ok(()) Ok(())
} }
#[tracing::instrument(skip(self))]
fn interrupt_par(&mut self) -> SourceResult<()> { fn interrupt_par(&mut self) -> SourceResult<()> {
self.interrupt_list()?; self.interrupt_list()?;
if !self.par.0.is_empty() { if !self.par.0.is_empty() {
@ -403,7 +400,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Ok(()) Ok(())
} }
#[tracing::instrument(skip_all)]
fn interrupt_page(&mut self, styles: Option<StyleChain<'a>>) -> SourceResult<()> { fn interrupt_page(&mut self, styles: Option<StyleChain<'a>>) -> SourceResult<()> {
self.interrupt_par()?; self.interrupt_par()?;
let Some(doc) = &mut self.doc else { return Ok(()) }; let Some(doc) = &mut self.doc else { return Ok(()) };

View File

@ -39,19 +39,16 @@ enum Attr {
impl Content { impl Content {
/// Create an empty element. /// Create an empty element.
#[tracing::instrument()]
pub fn new(func: ElemFunc) -> Self { pub fn new(func: ElemFunc) -> Self {
Self { func, attrs: EcoVec::new() } Self { func, attrs: EcoVec::new() }
} }
/// Create empty content. /// Create empty content.
#[tracing::instrument()]
pub fn empty() -> Self { pub fn empty() -> Self {
Self::new(SequenceElem::func()) Self::new(SequenceElem::func())
} }
/// Create a new sequence element from multiples elements. /// Create a new sequence element from multiples elements.
#[tracing::instrument(skip_all)]
pub fn sequence(iter: impl IntoIterator<Item = Self>) -> Self { pub fn sequence(iter: impl IntoIterator<Item = Self>) -> Self {
let mut iter = iter.into_iter(); let mut iter = iter.into_iter();
let Some(first) = iter.next() else { return Self::empty() }; let Some(first) = iter.next() else { return Self::empty() };
@ -94,7 +91,6 @@ impl Content {
} }
/// Access the child and styles. /// Access the child and styles.
#[tracing::instrument(skip_all)]
pub fn to_styled(&self) -> Option<(&Content, &Styles)> { pub fn to_styled(&self) -> Option<(&Content, &Styles)> {
if !self.is::<StyledElem>() { if !self.is::<StyledElem>() {
return None; return None;
@ -120,7 +116,6 @@ impl Content {
/// Cast to a trait object if the contained element has the given /// Cast to a trait object if the contained element has the given
/// capability. /// capability.
#[tracing::instrument(skip_all)]
pub fn with<C>(&self) -> Option<&C> pub fn with<C>(&self) -> Option<&C>
where where
C: ?Sized + 'static, C: ?Sized + 'static,
@ -132,7 +127,6 @@ impl Content {
/// Cast to a mutable trait object if the contained element has the given /// Cast to a mutable trait object if the contained element has the given
/// capability. /// capability.
#[tracing::instrument(skip_all)]
pub fn with_mut<C>(&mut self) -> Option<&mut C> pub fn with_mut<C>(&mut self) -> Option<&mut C>
where where
C: ?Sized + 'static, C: ?Sized + 'static,
@ -180,7 +174,6 @@ impl Content {
} }
/// Access a field on the content. /// Access a field on the content.
#[tracing::instrument(skip_all)]
pub fn field(&self, name: &str) -> Option<Value> { pub fn field(&self, name: &str) -> Option<Value> {
if let (Some(iter), "children") = (self.to_sequence(), name) { if let (Some(iter), "children") = (self.to_sequence(), name) {
Some(Value::Array(iter.cloned().map(Value::Content).collect())) Some(Value::Array(iter.cloned().map(Value::Content).collect()))

View File

@ -563,7 +563,6 @@ impl<'a> StyleChain<'a> {
/// The resulting style chain contains styles from `local` as well as /// The resulting style chain contains styles from `local` as well as
/// `self`. The ones from `local` take precedence over the ones from /// `self`. The ones from `local` take precedence over the ones from
/// `self`. For folded properties `local` contributes the inner value. /// `self`. For folded properties `local` contributes the inner value.
#[tracing::instrument(skip_all)]
pub fn chain<'b>(&'b self, local: &'b Styles) -> StyleChain<'b> { pub fn chain<'b>(&'b self, local: &'b Styles) -> StyleChain<'b> {
if local.is_empty() { if local.is_empty() {
*self *self
@ -573,7 +572,6 @@ impl<'a> StyleChain<'a> {
} }
/// Cast the first value for the given property in the chain. /// Cast the first value for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn get<T: Cast>( pub fn get<T: Cast>(
self, self,
func: ElemFunc, func: ElemFunc,
@ -587,7 +585,6 @@ impl<'a> StyleChain<'a> {
} }
/// Cast the first value for the given property in the chain. /// Cast the first value for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn get_resolve<T: Cast + Resolve>( pub fn get_resolve<T: Cast + Resolve>(
self, self,
func: ElemFunc, func: ElemFunc,
@ -599,7 +596,6 @@ impl<'a> StyleChain<'a> {
} }
/// Cast the first value for the given property in the chain. /// Cast the first value for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn get_fold<T: Cast + Fold>( pub fn get_fold<T: Cast + Fold>(
self, self,
func: ElemFunc, func: ElemFunc,
@ -621,7 +617,6 @@ impl<'a> StyleChain<'a> {
} }
/// Cast the first value for the given property in the chain. /// Cast the first value for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn get_resolve_fold<T>( pub fn get_resolve_fold<T>(
self, self,
func: ElemFunc, func: ElemFunc,
@ -656,7 +651,6 @@ impl<'a> StyleChain<'a> {
} }
/// Iterate over all values for the given property in the chain. /// Iterate over all values for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn properties<T: Cast + 'a>( pub fn properties<T: Cast + 'a>(
self, self,
func: ElemFunc, func: ElemFunc,

View File

@ -109,6 +109,7 @@ impl Source {
/// Returns the range in the new source that was ultimately reparsed. /// Returns the range in the new source that was ultimately reparsed.
/// ///
/// The method panics if the `replace` range is out of bounds. /// The method panics if the `replace` range is out of bounds.
#[track_caller]
pub fn edit(&mut self, replace: Range<usize>, with: &str) -> Range<usize> { pub fn edit(&mut self, replace: Range<usize>, with: &str) -> Range<usize> {
let start_byte = replace.start; let start_byte = replace.start;
let start_utf16 = self.byte_to_utf16(replace.start).unwrap(); let start_utf16 = self.byte_to_utf16(replace.start).unwrap();
@ -158,6 +159,7 @@ impl Source {
/// Map a span that points into this source file to a byte range. /// Map a span that points into this source file to a byte range.
/// ///
/// Panics if the span does not point into this source file. /// Panics if the span does not point into this source file.
#[track_caller]
pub fn range(&self, span: Span) -> Range<usize> { pub fn range(&self, span: Span) -> Range<usize> {
self.find(span) self.find(span)
.expect("span does not point into this source file") .expect("span does not point into this source file")

View File

@ -34,7 +34,6 @@ where
} }
/// Calculate a 128-bit siphash of a value. /// Calculate a 128-bit siphash of a value.
#[tracing::instrument(skip_all)]
pub fn hash128<T: Hash + ?Sized>(value: &T) -> u128 { pub fn hash128<T: Hash + ?Sized>(value: &T) -> u128 {
let mut state = SipHasher13::new(); let mut state = SipHasher13::new();
value.hash(&mut state); value.hash(&mut state);