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.
#[tracing::instrument(name = "grid layout", skip(self))]
pub fn layout(mut self) -> SourceResult<GridLayout> {
self.measure_columns()?;
@ -318,6 +317,7 @@ impl<'a, 'v> GridLayouter<'a, 'v> {
}
/// Determine all column sizes.
#[tracing::instrument(name = "GridLayouter::measure_columns", skip_all)]
fn measure_columns(&mut self) -> SourceResult<()> {
// Sum of sizes of resolved relative tracks.
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
/// be valid.
#[tracing::instrument(name = "Layout::measure", skip_all)]
fn measure(
&self,
vt: &mut Vt,
@ -198,6 +199,7 @@ fn realize_root<'a>(
}
/// Realize into an element that is capable of block-level layout.
#[tracing::instrument(skip_all)]
fn realize_block<'a>(
vt: &mut Vt,
scratch: &'a Scratch<'a>,
@ -261,7 +263,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
}
}
#[tracing::instrument(skip_all)]
fn accept(
&mut self,
mut content: &'a Content,
@ -327,7 +328,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
}
}
#[tracing::instrument(skip_all)]
fn styled(
&mut self,
elem: &'a Content,
@ -342,7 +342,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Ok(())
}
#[tracing::instrument(skip(self, local, outer))]
fn interrupt_style(
&mut self,
local: &Styles,
@ -377,7 +376,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Ok(())
}
#[tracing::instrument(skip(self))]
fn interrupt_list(&mut self) -> SourceResult<()> {
if !self.list.items.is_empty() {
let staged = mem::take(&mut self.list.staged);
@ -391,7 +389,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Ok(())
}
#[tracing::instrument(skip(self))]
fn interrupt_par(&mut self) -> SourceResult<()> {
self.interrupt_list()?;
if !self.par.0.is_empty() {
@ -403,7 +400,6 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
Ok(())
}
#[tracing::instrument(skip_all)]
fn interrupt_page(&mut self, styles: Option<StyleChain<'a>>) -> SourceResult<()> {
self.interrupt_par()?;
let Some(doc) = &mut self.doc else { return Ok(()) };

View File

@ -39,19 +39,16 @@ enum Attr {
impl Content {
/// Create an empty element.
#[tracing::instrument()]
pub fn new(func: ElemFunc) -> Self {
Self { func, attrs: EcoVec::new() }
}
/// Create empty content.
#[tracing::instrument()]
pub fn empty() -> Self {
Self::new(SequenceElem::func())
}
/// Create a new sequence element from multiples elements.
#[tracing::instrument(skip_all)]
pub fn sequence(iter: impl IntoIterator<Item = Self>) -> Self {
let mut iter = iter.into_iter();
let Some(first) = iter.next() else { return Self::empty() };
@ -94,7 +91,6 @@ impl Content {
}
/// Access the child and styles.
#[tracing::instrument(skip_all)]
pub fn to_styled(&self) -> Option<(&Content, &Styles)> {
if !self.is::<StyledElem>() {
return None;
@ -120,7 +116,6 @@ impl Content {
/// Cast to a trait object if the contained element has the given
/// capability.
#[tracing::instrument(skip_all)]
pub fn with<C>(&self) -> Option<&C>
where
C: ?Sized + 'static,
@ -132,7 +127,6 @@ impl Content {
/// Cast to a mutable trait object if the contained element has the given
/// capability.
#[tracing::instrument(skip_all)]
pub fn with_mut<C>(&mut self) -> Option<&mut C>
where
C: ?Sized + 'static,
@ -180,7 +174,6 @@ impl Content {
}
/// Access a field on the content.
#[tracing::instrument(skip_all)]
pub fn field(&self, name: &str) -> Option<Value> {
if let (Some(iter), "children") = (self.to_sequence(), name) {
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
/// `self`. The ones from `local` take precedence over the ones from
/// `self`. For folded properties `local` contributes the inner value.
#[tracing::instrument(skip_all)]
pub fn chain<'b>(&'b self, local: &'b Styles) -> StyleChain<'b> {
if local.is_empty() {
*self
@ -573,7 +572,6 @@ impl<'a> StyleChain<'a> {
}
/// Cast the first value for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn get<T: Cast>(
self,
func: ElemFunc,
@ -587,7 +585,6 @@ impl<'a> StyleChain<'a> {
}
/// Cast the first value for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn get_resolve<T: Cast + Resolve>(
self,
func: ElemFunc,
@ -599,7 +596,6 @@ impl<'a> StyleChain<'a> {
}
/// Cast the first value for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn get_fold<T: Cast + Fold>(
self,
func: ElemFunc,
@ -621,7 +617,6 @@ impl<'a> StyleChain<'a> {
}
/// Cast the first value for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn get_resolve_fold<T>(
self,
func: ElemFunc,
@ -656,7 +651,6 @@ impl<'a> StyleChain<'a> {
}
/// Iterate over all values for the given property in the chain.
#[tracing::instrument(skip_all)]
pub fn properties<T: Cast + 'a>(
self,
func: ElemFunc,

View File

@ -109,6 +109,7 @@ impl Source {
/// Returns the range in the new source that was ultimately reparsed.
///
/// 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> {
let start_byte = replace.start;
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.
///
/// Panics if the span does not point into this source file.
#[track_caller]
pub fn range(&self, span: Span) -> Range<usize> {
self.find(span)
.expect("span does not point into this source file")

View File

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