Increase cache size and pre-cache resolution

Improve performance by not caching pages which would have to be removed
from cache anyways
This commit is contained in:
Julian Mutter 2023-11-23 12:46:19 +01:00
parent 9240db298d
commit 78bc8b1e64
2 changed files with 10 additions and 3 deletions

View File

@ -51,6 +51,13 @@ impl PageCache {
pub fn cache_page(&mut self, page_number: PageNumber, height: i32) -> Option<CacheResponse> { pub fn cache_page(&mut self, page_number: PageNumber, height: i32) -> Option<CacheResponse> {
debug!("Caching page {}", page_number); debug!("Caching page {}", page_number);
if page_number.abs_diff(self.last_requested_page_number)
> self.max_num_stored_pages.div_ceil(2)
{
debug!("Page too far from reader, aborting caching call");
return None;
}
let begin_of_cashing = Instant::now(); let begin_of_cashing = Instant::now();
if let Some(page) = self.pages.get(&page_number) { if let Some(page) = self.pages.get(&page_number) {
if page.height() >= height { if page.height() >= height {
@ -217,7 +224,7 @@ impl SyncCacheCommandSender {
self.channel self.channel
.borrow_mut() .borrow_mut()
.cache_commands .cache_commands
.push_front(CachePageCommand { page, height: 10 }); // Cache with lower resolution .push_front(CachePageCommand { page, height: 100 }); // Cache with lower resolution
self.channel self.channel
.borrow_mut() .borrow_mut()
.cache_commands .cache_commands
@ -248,7 +255,7 @@ where
{ {
let (command_sender, command_receiver) = SyncCacheCommandChannel::open(); let (command_sender, command_receiver) = SyncCacheCommandChannel::open();
let mut cache = PageCache::new(document, 20); let mut cache = PageCache::new(document, 30);
// Besides the name, it is not in another thread // Besides the name, it is not in another thread
glib::spawn_future_local(async move { glib::spawn_future_local(async move {

View File

@ -7,7 +7,7 @@ use log::debug;
use poppler::Page; use poppler::Page;
pub fn draw_pages_to_texture(pages: &[Rc<Page>], area_height: i32) -> Texture { pub fn draw_pages_to_texture(pages: &[Rc<Page>], area_height: i32) -> Texture {
let area_height = i32::max(10, area_height); let area_height = i32::max(100, area_height);
let total_width_normalized: f64 = pages let total_width_normalized: f64 = pages
.iter() .iter()
.map(|page| page.size()) .map(|page| page.size())