mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Cache: Rewrite based on lua-lru
Ought to be faster than our naive array-based approach. Especially for the glyph cache, which has a solid amount of elements, and is mostly cache hits. (There are few things worse for performance in Lua than table.remove @ !tail and table.insert @ !tail, which this was full of :/). DocCache: New module that's now an actual Cache instance instead of a weird hack. Replaces "Cache" (the instance) as used across Document & co. Only Cache instance with on-disk persistence. ImageCache: Update to new Cache. GlyphCache: Update to new Cache. Also, actually free glyph bbs on eviction.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
local Cache = require("cache")
|
||||
local CacheItem = require("cacheitem")
|
||||
local CanvasContext = require("document/canvascontext")
|
||||
local DocCache = require("document/doccache")
|
||||
local DocSettings = require("docsettings")
|
||||
local Document = require("document/document")
|
||||
local DrawContext = require("ffi/drawcontext")
|
||||
@@ -139,7 +139,7 @@ end
|
||||
|
||||
function PdfDocument:getUsedBBox(pageno)
|
||||
local hash = "pgubbox|"..self.file.."|"..self.reflowable_font_size.."|"..pageno
|
||||
local cached = Cache:check(hash)
|
||||
local cached = DocCache:check(hash)
|
||||
if cached then
|
||||
return cached.ubbox
|
||||
end
|
||||
@@ -152,7 +152,7 @@ function PdfDocument:getUsedBBox(pageno)
|
||||
if used.x1 > pwidth then used.x1 = pwidth end
|
||||
if used.y0 < 0 then used.y0 = 0 end
|
||||
if used.y1 > pheight then used.y1 = pheight end
|
||||
Cache:insert(hash, CacheItem:new{
|
||||
DocCache:insert(hash, CacheItem:new{
|
||||
ubbox = used,
|
||||
size = 256, -- might be closer to 160
|
||||
})
|
||||
@@ -162,13 +162,13 @@ end
|
||||
|
||||
function PdfDocument:getPageLinks(pageno)
|
||||
local hash = "pglinks|"..self.file.."|"..self.reflowable_font_size.."|"..pageno
|
||||
local cached = Cache:check(hash)
|
||||
local cached = DocCache:check(hash)
|
||||
if cached then
|
||||
return cached.links
|
||||
end
|
||||
local page = self._document:openPage(pageno)
|
||||
local links = page:getPageLinks()
|
||||
Cache:insert(hash, CacheItem:new{
|
||||
DocCache:insert(hash, CacheItem:new{
|
||||
links = links,
|
||||
size = 64 + (8 * 32 * #links),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user