Skip to content

Commit

Permalink
Merge pull request #125 from pamburus/feature/scanner-performance-4
Browse files Browse the repository at this point in the history
new: Minor performance improvement
  • Loading branch information
pamburus authored Jan 28, 2024
2 parents 8127c8b + 3705725 commit 7c7349f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.25.1-beta.3"
version = "0.25.1-beta.4"
edition = "2021"
build = "build.rs"

Expand Down
14 changes: 7 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::os::unix::fs::MetadataExt;

// third-party imports
use closure::closure;
use crossbeam_channel::{self as channel, Receiver, RecvError, Sender,RecvTimeoutError};
use crossbeam_channel::{self as channel, Receiver, RecvError, Sender, RecvTimeoutError};
use crossbeam_utils::thread;
use itertools::{izip, Itertools};
use platform_dirs::AppDirs;
Expand All @@ -34,7 +34,7 @@ use crate::formatting::{RecordFormatter, RecordWithSourceFormatter, RawRecordFor
use crate::index::{Indexer, Timestamp};
use crate::input::{BlockLine, InputHolder, InputReference, Input};
use crate::model::{Filter, Parser, ParserSettings, RawRecord, Record, RecordFilter, RecordWithSourceConstructor};
use crate::scanning::{BufFactory, Scanner, Segment, SegmentBufFactory};
use crate::scanning::{BufFactory, Scanner, Segment, SegmentBuf, SegmentBufFactory};
use crate::serdex::StreamDeserializerWithOffsets;
use crate::settings::{Fields, Formatting};
use crate::theme::{Element, StylingPush, Theme};
Expand Down Expand Up @@ -132,7 +132,7 @@ impl App {
// prepare receive/transmit channels for input data
let (txi, rxi): (Vec<_>, Vec<_>) = (0..n).map(|_| channel::bounded(1)).unzip();
// prepare receive/transmit channels for output data
let (txo, rxo): (Vec<_>, Vec<_>) = (0..n).into_iter().map(|_| channel::bounded::<(usize, Vec<u8>)>(1)).unzip();
let (txo, rxo): (Vec<_>, Vec<_>) = (0..n).into_iter().map(|_| channel::bounded::<(usize, SegmentBuf)>(1)).unzip();
// spawn reader thread
let reader = scope.spawn(closure!(clone sfi, |_| -> Result<()> {
let mut tx = StripedSender::new(txi);
Expand All @@ -157,12 +157,12 @@ impl App {
let mut buf = bfo.new_buf();
processor.process(segment.data(), &mut buf, prefix, &mut RecordIgnorer{});
sfi.recycle(segment);
if let Err(_) = txo.send((i, buf)) {
if let Err(_) = txo.send((i, buf.into())) {
break;
};
}
Segment::Incomplete(segment, _) => {
if let Err(_) = txo.send((i, segment.to_vec())) {
if let Err(_) = txo.send((i, segment)) {
break;
}
}
Expand All @@ -173,8 +173,8 @@ impl App {
// spawn writer thread
let writer = scope.spawn(closure!(ref bfo, |_| -> Result<()> {
for (_, buf) in StripedReceiver::new(rxo) {
output.write_all(&buf[..])?;
bfo.recycle(buf);
output.write_all(buf.data())?;
bfo.recycle(buf.into_inner());
}
Ok(())
}));
Expand Down
5 changes: 2 additions & 3 deletions src/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ impl SegmentBuf {
}

/// Converts the SegmentBuf to a Vec<u8>.
pub fn to_vec(mut self) -> Vec<u8> {
self.data.resize(self.size, 0);
pub fn into_inner(self) -> Vec<u8> {
self.data
}

Expand Down Expand Up @@ -110,7 +109,7 @@ impl<T: AsRef<[u8]>> From<T> for SegmentBuf {
// ---

/// Segment is an output of Scanner.
/// Complete segment cantains a whole number of tokens.
/// Complete segment contains a whole number of tokens.
/// Incomplete segment contains a part of a token.
#[derive(Debug, Eq, PartialEq)]
pub enum Segment {
Expand Down

0 comments on commit 7c7349f

Please sign in to comment.