mirror of
https://github.com/itsjunetime/tdf.git
synced 2026-06-01 23:51:46 -04:00
Dramatically improve search performance by pausing rendering every once-in-a-while
This commit is contained in:
@@ -10,7 +10,7 @@ use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main, profile
|
||||
use futures_util::StreamExt;
|
||||
use tdf::{
|
||||
converter::{ConvertedPage, ConverterMsg},
|
||||
renderer::{fill_default, PageInfo, RenderInfo}
|
||||
renderer::{PageInfo, RenderInfo, fill_default}
|
||||
};
|
||||
use utils::{
|
||||
RenderState, handle_converter_msg, handle_renderer_msg, render_doc, start_all_rendering,
|
||||
@@ -120,7 +120,7 @@ async fn render_all_files(path: &'static str) -> Vec<PageInfo> {
|
||||
|
||||
while let Some(info) = from_render_rx.next().await {
|
||||
match info.expect("Renderer ran into an error while rendering") {
|
||||
RenderInfo::Reloaded => (),
|
||||
RenderInfo::Reloaded | RenderInfo::SearchResults { .. } => (),
|
||||
RenderInfo::NumPages(num) => fill_default(&mut pages, num),
|
||||
RenderInfo::Page(page) => {
|
||||
let num = page.page_num;
|
||||
|
||||
+14
-4
@@ -21,8 +21,8 @@ pub fn handle_renderer_msg(
|
||||
to_converter_tx.send(ConverterMsg::NumPages(num)).unwrap();
|
||||
}
|
||||
Ok(RenderInfo::Page(info)) => to_converter_tx.send(ConverterMsg::AddImg(info)).unwrap(),
|
||||
// We can ignore the `Reloaded` variant 'cause that's only used to send info to the TUI
|
||||
Ok(RenderInfo::Reloaded) => (),
|
||||
// We can ignore the these variants 'cause they're only used to send info to the TUI
|
||||
Ok(RenderInfo::Reloaded | RenderInfo::SearchResults { .. }) => (),
|
||||
Err(e) => panic!("Got error from renderer: {e:?}")
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,15 @@ pub fn start_rendering_loop(
|
||||
width: columns * FONT_SIZE.0
|
||||
};
|
||||
|
||||
std::thread::spawn(move || start_rendering(&str_path, to_main_tx, from_main_rx, size));
|
||||
std::thread::spawn(move || {
|
||||
start_rendering(
|
||||
&str_path,
|
||||
to_main_tx,
|
||||
from_main_rx,
|
||||
size,
|
||||
tdf::PrerenderLimit::All
|
||||
)
|
||||
});
|
||||
|
||||
let main_area = Rect {
|
||||
x: 0,
|
||||
@@ -139,7 +147,9 @@ pub async fn render_doc(path: impl AsRef<Path>, search_term: Option<&str>) {
|
||||
} = start_all_rendering(path);
|
||||
|
||||
if let Some(term) = search_term {
|
||||
to_render_tx.send(RenderNotif::Search(term.to_owned())).unwrap();
|
||||
to_render_tx
|
||||
.send(RenderNotif::Search(term.to_owned()))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
while pages.is_empty() || pages.iter().any(Option::is_none) {
|
||||
|
||||
Reference in New Issue
Block a user