Improve tlparse runtime by caching format_stack results#173
Conversation
e1aa79e to
bcb3702
Compare
aorenste
left a comment
There was a problem hiding this comment.
As a follow-on you could use rayon to do the syntax highlighting in parallel to speed it up quite a bit.
Approving w/ comments.
| caption: &str, | ||
| open: bool, | ||
| ) -> String { | ||
| let key = (stack.clone(), caption.to_string()); |
There was a problem hiding this comment.
You're not including open in the cache key? Should probably include it - but it looks like it's always false? So you could just remove it from the function.
There was a problem hiding this comment.
good catch! removing it
| caption: &str, | ||
| open: bool, | ||
| ) -> String { | ||
| let key = (stack.clone(), caption.to_string()); |
There was a problem hiding this comment.
I don't like these clones, but unfortunately HashMap has a limitation that requires it for a tuple key. If we find that this is a perf bottleneck later we could switch to a 2-level cache (i.e. FxHashMap<StackSummary, FxHashMap<String, String>>) which wouldn't require us to clone the key - but that's proabably not necessary.
| return cached.clone(); | ||
| } | ||
| let result = format_stack(stack, caption, open); | ||
| cache.insert(key, result.clone()); |
There was a problem hiding this comment.
We could avoid this clone by returning the copy of the String the cache contains as a &str - but again... probably overkill.
src/parsers.rs
Outdated
| false, | ||
| ), | ||
| .map(|spec| { | ||
| let user_stack = spec.user_stack.unwrap_or(Vec::new()); |
There was a problem hiding this comment.
nit: only create the Vec if the unwrap fails (here and all the unwrap_or below):
| let user_stack = spec.user_stack.unwrap_or(Vec::new()); | |
| let user_stack = spec.user_stack.unwrap_or_else(|| Vec::new()); |
bcb3702 to
a2ce87a
Compare
Summary
Cache expensive repeated computations in
compilation_metricsandinductor_output_codeparsers to significantly reduce parsing time on large log files.Changes
simplify_filename(types.rs): Replace per-callRegex::new()with astatic Lazy<Regex>, eliminating ~3000 regex compilations per run.parsers.rs): LoadSyntaxSetandThemeSetonce viaOnceLockinstead of on everygenerate_html_outputcall.format_stackresults (parsers.rs): Deduplicate repeatedformat_stackcalls using aFxHashMap<(StackSummary, String), String>cache. Reduces ~3000 expensive trie-building calls to ~20 unique computations for the worst-case entries.Benchmark (release build, 258MB log, 44,826 entries, 3 runs each) on my macbook air.
this log has a lot of symbols and guards added (300+)
Parser-level breakdown (after fixes):
inductor_output_codecompilation_metricsCurrently
inductor_output_codetakes a long time, and that's mostly spend on highlighting the syntax.If we use
--plain-textto not do highlighting:Test plan
cargo testpassesdiffon output directories shows no differences)