From 91ab9de617f57731a4b20a78b53b776b60725b69 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Fri, 29 Dec 2023 13:23:08 +0100 Subject: [PATCH 1/3] fix: removed unneeded assignment that led to performance regression --- src/scanning.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/scanning.rs b/src/scanning.rs index 11150717..e0b80e98 100644 --- a/src/scanning.rs +++ b/src/scanning.rs @@ -303,7 +303,6 @@ impl<'a, 'b> Iterator for ScannerIter<'a, 'b> { }; let result = self.next.replace(next); - self.placement = placement; return if result.size != 0 { Some(Ok(Segment::new(result, placement))) } else { From caa94af1bbf8bc36253a93487b734fca3c879e22 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Fri, 29 Dec 2023 13:23:29 +0100 Subject: [PATCH 2/3] new: forced inline for several functions --- src/app.rs | 1 + src/formatting.rs | 3 +++ src/model.rs | 33 +++++++++++++++++++++++++++++++++ src/serdex.rs | 2 ++ 4 files changed, 39 insertions(+) diff --git a/src/app.rs b/src/app.rs index decd1eb1..e9454103 100644 --- a/src/app.rs +++ b/src/app.rs @@ -729,6 +729,7 @@ impl<'a, Formatter: RecordWithSourceFormatter, Filter: RecordFilter> SegmentProc } } + #[inline(always)] fn show_unparsed(&self) -> bool { self.options.allow_unparsed_data } diff --git a/src/formatting.rs b/src/formatting.rs index 56e95db5..c8ef9d4f 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -31,18 +31,21 @@ pub trait RecordWithSourceFormatter { pub struct RawRecordFormatter {} impl RecordWithSourceFormatter for RawRecordFormatter { + #[inline(always)] fn format_record(&self, buf: &mut Buf, rec: model::RecordWithSource) { buf.extend_from_slice(rec.source); } } impl RecordWithSourceFormatter for &T { + #[inline(always)] fn format_record(&self, buf: &mut Buf, rec: model::RecordWithSource) { (**self).format_record(buf, rec) } } impl RecordWithSourceFormatter for Box { + #[inline(always)] fn format_record(&self, buf: &mut Buf, rec: model::RecordWithSource) { (**self).format_record(buf, rec) } diff --git a/src/model.rs b/src/model.rs index 52e8b066..659986cd 100644 --- a/src/model.rs +++ b/src/model.rs @@ -38,18 +38,22 @@ pub struct Record<'a> { } impl<'a> Record<'a> { + #[inline(always)] pub fn fields(&self) -> impl Iterator { self.extra.iter().chain(self.extrax.iter()) } + #[inline(always)] pub fn fields_for_search(&self) -> impl Iterator { self.fields().chain(self.predefined.iter()) } + #[inline(always)] pub fn matches(&self, filter: F) -> bool { filter.apply(self) } + #[inline(always)] pub fn with_prefix(mut self, prefix: &'a [u8]) -> Self { self.prefix = Some(prefix); @@ -96,12 +100,14 @@ pub struct RecordWithSource<'a> { } impl<'a> RecordWithSource<'a> { + #[inline(always)] pub fn new(record: &'a Record<'a>, source: &'a [u8]) -> Self { Self { record, source } } } impl RecordWithSourceConstructor for Record<'_> { + #[inline(always)] fn with_source<'a>(&'a self, source: &'a [u8]) -> RecordWithSource<'a> { RecordWithSource::new(self, source) } @@ -112,6 +118,7 @@ impl RecordWithSourceConstructor for Record<'_> { pub trait RecordFilter { fn apply<'a>(&self, record: &'a Record<'a>) -> bool; + #[inline(always)] fn and(self, rhs: F) -> RecordFilterAnd where Self: Sized, @@ -120,6 +127,7 @@ pub trait RecordFilter { RecordFilterAnd { lhs: self, rhs } } + #[inline(always)] fn or(self, rhs: F) -> RecordFilterOr where Self: Sized, @@ -130,18 +138,21 @@ pub trait RecordFilter { } impl RecordFilter for Box { + #[inline(always)] fn apply<'a>(&self, record: &'a Record<'a>) -> bool { (**self).apply(record) } } impl RecordFilter for &T { + #[inline(always)] fn apply<'a>(&self, record: &'a Record<'a>) -> bool { (**self).apply(record) } } impl RecordFilter for Option { + #[inline(always)] fn apply<'a>(&self, record: &'a Record<'a>) -> bool { if let Some(filter) = self { filter.apply(record) @@ -159,6 +170,7 @@ pub struct RecordFilterAnd { } impl RecordFilter for RecordFilterAnd { + #[inline(always)] fn apply<'a>(&self, record: &'a Record<'a>) -> bool { self.lhs.apply(record) && self.rhs.apply(record) } @@ -172,6 +184,7 @@ pub struct RecordFilterOr { } impl RecordFilter for RecordFilterOr { + #[inline(always)] fn apply<'a>(&self, record: &'a Record<'a>) -> bool { self.lhs.apply(record) || self.rhs.apply(record) } @@ -182,6 +195,7 @@ impl RecordFilter for RecordFilterOr { pub struct RecordFilterNone; impl RecordFilter for RecordFilterNone { + #[inline(always)] fn apply<'a>(&self, _: &'a Record<'a>) -> bool { true } @@ -280,10 +294,12 @@ impl ParserSettings { } } + #[inline(always)] fn apply<'a>(&self, key: &'a str, value: &'a RawValue, to: &mut Record<'a>, pc: &mut PriorityController) { self.blocks[0].apply(self, key, value, to, pc, true); } + #[inline(always)] fn apply_each<'a, 'i, I>(&self, items: I, to: &mut Record<'a>) where I: IntoIterator, @@ -293,6 +309,7 @@ impl ParserSettings { self.apply_each_ctx(items, to, &mut pc); } + #[inline(always)] fn apply_each_ctx<'a, 'i, I>(&self, items: I, to: &mut Record<'a>, pc: &mut PriorityController) where I: IntoIterator, @@ -351,6 +368,7 @@ impl ParserSettingsBlock { } } + #[inline(always)] fn apply_each_ctx<'a, 'i, I>( &self, ps: &ParserSettings, @@ -382,6 +400,7 @@ struct PriorityController { } impl PriorityController { + #[inline(always)] fn prioritize ()>(&mut self, kind: FieldKind, priority: usize, update: F) -> bool { let p = match kind { FieldKind::Time => &mut self.time, @@ -466,6 +485,7 @@ impl FieldSettings { } } + #[inline(always)] fn apply_ctx<'a>( &self, ps: &ParserSettings, @@ -486,6 +506,7 @@ impl FieldSettings { } } + #[inline(always)] fn kind(&self) -> Option { match self { Self::Time => Some(FieldKind::Time), @@ -530,6 +551,7 @@ pub struct RawRecord<'a> { } impl<'a> RawRecord<'a> { + #[inline(always)] pub fn fields(&self) -> impl Iterator { self.fields.iter().chain(self.fieldsx.iter()) } @@ -551,6 +573,7 @@ struct RawRecordVisitor<'a> { } impl<'a> RawRecordVisitor<'a> { + #[inline(always)] fn new() -> Self { Self { marker: PhantomData } } @@ -596,6 +619,7 @@ pub struct KeyMatcher<'a> { } impl<'a> KeyMatcher<'a> { + #[inline(always)] pub fn new(key: &'a str) -> Self { Self { key } } @@ -624,6 +648,7 @@ impl<'a> KeyMatcher<'a> { } } + #[inline(always)] fn norm(c: char) -> char { if c == '_' { '-' @@ -704,6 +729,7 @@ impl UnaryBoolOp { } impl Default for UnaryBoolOp { + #[inline(always)] fn default() -> Self { Self::None } @@ -718,6 +744,7 @@ pub enum FieldFilterKey { } impl FieldFilterKey { + #[inline(always)] pub fn borrowed(&self) -> FieldFilterKey<&str> { match self { FieldFilterKey::Predefined(kind) => FieldFilterKey::Predefined(*kind), @@ -797,6 +824,7 @@ impl FieldFilter { }) } + #[inline(always)] fn match_custom_key<'a>(&'a self, key: &str) -> Option> { if let FieldFilterKey::Custom(k) = &self.key { if self.flat_key && k.len() != key.len() { @@ -925,6 +953,7 @@ impl FieldFilterSet { } impl RecordFilter for FieldFilterSet { + #[inline(always)] fn apply<'a>(&self, record: &'a Record<'a>) -> bool { self.0.iter().all(|field| field.apply(record)) } @@ -941,6 +970,7 @@ pub struct Filter { } impl Filter { + #[inline(always)] pub fn is_empty(&self) -> bool { self.fields.0.is_empty() && self.level.is_none() && self.since.is_none() && self.until.is_none() } @@ -991,6 +1021,7 @@ struct ObjectVisitor<'a> { marker: PhantomData Object<'a>>, } impl<'a> ObjectVisitor<'a> { + #[inline(always)] fn new() -> Self { Self { marker: PhantomData } } @@ -1028,6 +1059,7 @@ pub struct Array<'a, const N: usize> { } impl<'a, const N: usize> Array<'a, N> { + #[inline(always)] pub fn iter(&self) -> impl Iterator { self.items.iter().chain(self.more.iter()) } @@ -1037,6 +1069,7 @@ struct ArrayVisitor<'a, const N: usize> { marker: PhantomData Array<'a, N>>, } impl<'a, const N: usize> ArrayVisitor<'a, N> { + #[inline(always)] fn new() -> Self { Self { marker: PhantomData } } diff --git a/src/serdex.rs b/src/serdex.rs index e1d7fb2b..9d742f7e 100644 --- a/src/serdex.rs +++ b/src/serdex.rs @@ -9,6 +9,8 @@ where T: serde::de::Deserialize<'de>, { type Item = serde_json::Result<(T, Range)>; + + #[inline(always)] fn next(&mut self) -> Option { let start_offset = self.0.byte_offset(); self.0 From 87fea5c5b88e25a37a19dc503e73ecef60409b9a Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Fri, 29 Dec 2023 13:24:30 +0100 Subject: [PATCH 3/3] new: changed version to 0.24.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3e292ab7..87561959 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -717,7 +717,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hl" -version = "0.24.0" +version = "0.24.1" dependencies = [ "atoi", "bincode", diff --git a/Cargo.toml b/Cargo.toml index 8b9b7c5e..6095ffc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ categories = ["command-line-utilities"] description = "Utility for viewing json-formatted log files." keywords = ["cli", "human", "log"] name = "hl" -version = "0.24.0" +version = "0.24.1" edition = "2021" build = "build.rs"