summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-otl.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2017-08-13 17:00:01 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2017-08-13 17:00:01 +0200
commit3ac1a4bbf84101cca4e80acb31eb7fc5754248d3 (patch)
tree3d97b1742ef8bca623e24328b94ecabcec3d2285 /tex/context/base/mkiv/font-otl.lua
parent75db37fb5f8e98bbd8a702ff1d0e765015bab61f (diff)
downloadcontext-3ac1a4bbf84101cca4e80acb31eb7fc5754248d3.tar.gz
2017-08-13 16:44:00
Diffstat (limited to 'tex/context/base/mkiv/font-otl.lua')
-rw-r--r--tex/context/base/mkiv/font-otl.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/font-otl.lua b/tex/context/base/mkiv/font-otl.lua
index 4625c5aaf..6f71f837f 100644
--- a/tex/context/base/mkiv/font-otl.lua
+++ b/tex/context/base/mkiv/font-otl.lua
@@ -101,6 +101,33 @@ registerdirective("fonts.otf.loader.forcenotdef", function(v) forcenotdef =
registerotfenhancer("check extra features", function() end) -- placeholder
+-- Kai has memory problems on osx so here is an experiment (I only tested on windows as
+-- my test mac is old and gets no updates and is therefore rather useless.):
+
+local checkmemory = utilities.lua and utilities.lua.checkmemory
+local threshold = 100 -- MB
+local tracememory = false
+
+registertracker("fonts.otf.loader.memory",function(v) tracememory = v end)
+
+if not checkmemory then -- we need a generic plug (this code might move):
+
+ local collectgarbage = collectgarbage
+
+ checkmemory = function(previous,threshold) -- threshold in MB
+ local current = collectgarbage("count")
+ if previous then
+ local checked = (threshold or 64)*1024
+ if current - previous > checked then
+ collectgarbage("collect")
+ current = collectgarbage("count")
+ end
+ end
+ return current
+ end
+
+end
+
function otf.load(filename,sub,instance)
local base = file.basename(file.removesuffix(filename))
local name = file.removesuffix(base) -- already no suffix
@@ -132,9 +159,13 @@ function otf.load(filename,sub,instance)
data = otfreaders.loadfont(filename,sub or 1,instance) -- we can pass the number instead (if it comes from a name search)
if data then
-- todo: make this a plugin
+ local used = checkmemory()
local resources = data.resources
local svgshapes = resources.svgshapes
local sbixshapes = resources.sbixshapes
+ if cleanup == 0 then
+ checkmemory(used,threshold,tracememory)
+ end
if svgshapes then
resources.svgshapes = nil
if otf.svgenabled then
@@ -149,6 +180,11 @@ function otf.load(filename,sub,instance)
timestamp = timestamp,
}
end
+ if cleanup > 1 then
+ collectgarbage("collect")
+ else
+ checkmemory(used,threshold,tracememory)
+ end
end
if sbixshapes then
resources.sbixshapes = nil
@@ -164,18 +200,31 @@ function otf.load(filename,sub,instance)
timestamp = timestamp,
}
end
+ if cleanup > 1 then
+ collectgarbage("collect")
+ else
+ checkmemory(used,threshold,tracememory)
+ end
end
--
otfreaders.compact(data)
+ if cleanup == 0 then
+ checkmemory(used,threshold,tracememory)
+ end
otfreaders.rehash(data,"unicodes")
otfreaders.addunicodetable(data)
otfreaders.extend(data)
+ if cleanup == 0 then
+ checkmemory(used,threshold,tracememory)
+ end
otfreaders.pack(data)
report_otf("loading done")
report_otf("saving %a in cache",filename)
data = containers.write(otf.cache, hash, data)
if cleanup > 1 then
collectgarbage("collect")
+ else
+ checkmemory(used,threshold,tracememory)
end
stoptiming(otfreaders)
if elapsedtime then
@@ -183,10 +232,14 @@ function otf.load(filename,sub,instance)
end
if cleanup > 3 then
collectgarbage("collect")
+ else
+ checkmemory(used,threshold,tracememory)
end
data = containers.read(otf.cache,hash) -- this frees the old table and load the sparse one
if cleanup > 2 then
collectgarbage("collect")
+ else
+ checkmemory(used,threshold,tracememory)
end
else
data = nil