notable near 2x speedup in load time, and near 3x reduction in memory consumption

This commit is contained in:
Yehowshua Immanuel 2022-08-11 19:58:21 -04:00
parent def4b26005
commit fd31ec1358
4 changed files with 15 additions and 53 deletions

View file

@ -21,9 +21,11 @@ fn main() -> std::io::Result<()> {
let file = File::open(&args.path)?;
let vcd = parse_vcd(file).unwrap();
// vcd.
let elapsed = now.elapsed();
println!("Elapsed: {:.2?}", elapsed);
std::thread::sleep(std::time::Duration::from_secs(10));
Ok(())
}

View file

@ -5,9 +5,6 @@ pub(super) fn parse_events<'a>(
vcd: &'a mut VCD,
signal_map: &mut HashMap<String, SignalIdx>,
) -> Result<(), String> {
// let hash_time = std::time::Duration::ZERO;
// let hash_time = std::time::Duration::ZERO;
loop {
let next_word = word_reader.next_word();
@ -18,7 +15,7 @@ pub(super) fn parse_events<'a>(
break;
};
let (word, cursor) = next_word.unwrap();
let (word, cursor) = next_word!(word_reader)?;
let Cursor(Line(_), Word(word_in_line_idx)) = cursor;
// we only want to match on the first word in a line
if word_in_line_idx != 1 {
@ -29,10 +26,13 @@ pub(super) fn parse_events<'a>(
"#" => {
let value = &word[1..];
let (f, l) = (file!(), line!());
let value = BigInt::parse_bytes(value.as_bytes(), 10).ok_or(
format!("Error near {f}:{l}. Failed to parse {value} as BigInt at {cursor:?}")
.as_str(),
)?;
let value = BigInt::parse_bytes(value.as_bytes(), 10)
.ok_or(())
.map_err(|_| {
format!(
"Error near {f}:{l}. Failed to parse {value} as BigInt at {cursor:?}"
)
})?;
let (_, mut value) = value.to_bytes_le();
// TODO : u32 helps with less memory, but should ideally likely be
// configurable.
@ -177,6 +177,7 @@ pub(super) fn parse_events<'a>(
(num_bits / 8) + if (num_bits % 8) > 0 { 1 } else { 0 };
while curr_num_bytes < bytes_required {
// TODO: remove once library is known to be stable
// useful for debugging
// let err = format!("Error at {cursor:?}.\
// num_bits = {num_bits}, \

View file

@ -183,8 +183,7 @@ pub(super) fn parse_timescale(
file!(),
line!()
)),
}
.unwrap();
}?;
(Some(scalar), unit)
} else {
@ -200,8 +199,7 @@ pub(super) fn parse_timescale(
file!(),
line!()
)),
}
.unwrap();
}?;
(Some(scalar), unit)
}
@ -293,7 +291,7 @@ pub(super) fn parse_metadata(word_reader: &mut WordReader) -> Result<Metadata, S
// store date and exit loop if a match is found
if parsed_date.is_ok() {
metadata.date = Some(parsed_date.unwrap());
metadata.date = Some(parsed_date?);
break;
}
}

View file

@ -127,42 +127,3 @@ macro_rules! curr_word {
pub(super) use curr_word;
pub(super) use next_word;
// fn previous_symbol(level: u32) -> Option<BacktraceSymbol> {
// let (trace, curr_file, curr_line) = (Backtrace::new(), file!(), line!());
// let frames = trace.frames();
// frames
// .iter()
// .flat_map(BacktraceFrame::symbols)
// .skip_while(|s| {
// s.filename()
// .map(|p| !p.ends_with(curr_file))
// .unwrap_or(true)
// || s.lineno() != Some(curr_line)
// })
// .nth(1 + level as usize)
// .cloned()
// }
// impl From<FileStatus> for String {
// fn from(f: FileStatus) -> String {
// let sym = previous_symbol(1);
// let filename = sym
// .as_ref()
// .and_then(BacktraceSymbol::filename)
// .map_or(None, |path| path.to_str())
// .unwrap_or("(Couldn't determine filename)");
// let lineno = sym
// .as_ref()
// .and_then(BacktraceSymbol::lineno)
// .map_or(None, |path| Some(path.to_string()))
// .unwrap_or("(Couldn't determine line number)".to_string());
// match f {
// FileStatus::Eof => format!(
// "Error near {filename}:{lineno} \
// No more words left in vcd file."
// ),
// }
// }
// }