Hi Hans, TeX Live contains ~31 times as many files as the ConTeXt distribution, so running "mtxrun --generate" is relatively slow. However, TeX Live already generates a filename index for all its files, so if we use that instead of traversing the filesystem, "mtxrun --generate" runs quite a bit quicker. My testing shows that currently "mtxrun --generate" takes 2.7 seconds to run, and with this patch it takes 1.5 seconds; real-world results will likely show an even greater difference since I tested it with repeated runs (so the OS has cached everything) and I have really fast disks.
I've included a diff inline below, and I've also attached the modified
files. I didn't attach mtxrun.lua since the file is so large, so you'll
need to manually copy the changes from the diff.
Also, can you please rename m-texlive.mkxl to m-texlive.mkiv? LuaTeX
doesn't find the file with the ".mkxl" suffix, and I'd like to keep
supporting MkIV in TeX Live.
Thanks,
-- Max
diff --git a/tex/context/base/mkiv/data-fil.lua
b/tex/context/base/mkiv/data-fil.lua
index 8dbc8a0..1f7ff94 100644
--- a/tex/context/base/mkiv/data-fil.lua
+++ b/tex/context/base/mkiv/data-fil.lua
@@ -45,7 +45,13 @@ end
function resolvers.generators.file(specification)
local pathname = specification.filename
- local content = scanfiles(pathname,false,true) -- scan once
+
+ local content
+ if resolvers.target() == "texlive" then
+ content = resolvers.scantexlive(pathname,false,true)
+ else
+ content = scanfiles(pathname,false,true) -- scan once
+ end
registerfilehash(pathname,content,true)
end
diff --git a/tex/context/base/mkiv/data-res.lua
b/tex/context/base/mkiv/data-res.lua
index a1b6795..114d780 100644
--- a/tex/context/base/mkiv/data-res.lua
+++ b/tex/context/base/mkiv/data-res.lua
@@ -489,6 +489,9 @@ local function load_configuration_files()
end
end
end
+ if data and data.target and data.target ~= "" then
+ instance.target = data.target
+ end
data = data and data.content
if data then
if trace_locating then
@@ -2042,3 +2045,11 @@ function resolvers.knownvariables(pattern)
return { }
end
end
+
+function resolvers.target()
+ if instance and instance.target then
+ return instance.target
+ else
+ return "context"
+ end
+end
diff --git a/tex/context/base/mkiv/data-tld.lua
b/tex/context/base/mkiv/data-tld.lua
index f6e3286..c1b27d3 100644
--- a/tex/context/base/mkiv/data-tld.lua
+++ b/tex/context/base/mkiv/data-tld.lua
@@ -6,6 +6,7 @@ if not modules then modules = { } end modules ['data-tld'] = {
license = "see context related readme files",
}
+local report = logs.reporter("resolvers","texlive")
-- This is a variant on code I found in a \TEXLIVE\ installation in \type
-- {cont-sys.mkxl} in 2025 (probably written by Max). See \type
{m-texlive.mkxl}.
@@ -67,3 +68,99 @@ function resolvers.checktexlive(texlive)
end
end
end
+
+function resolvers.scantexlive(path, ...)
+ local realpath = resolvers.resolve(path)
+ local lsrfile = file.join(realpath, "ls-R")
+ if lfs.isfile(lsrfile) then
+ return resolvers.parselsr(lsrfile, path)
+ else
+ return resolvers.scanfiles(path, ...)
+ end
+end
+
+function resolvers.parselsr(lsrfile, path)
+ local content = io.loaddata(lsrfile)
+ if not content or content == "" then
+ report("no content in ls-R file %a", lsrfile)
+ return
+ end
+
+ --[[ slower
+ local files, remap, directories = { }, { }, { }
+ local n_files, n_remap, n_directories = 0, 0, 0
+ local sections = content:split("\n\n")
+ for _, section in ipairs(sections) do
+ if section:match("^%%") then
+ goto continue
+ end
+ local lines = section:split("\n")
+ local base = lines[1]:sub(3, -2)
+
+ directories[base] = lines
+ n_directories = n_directories + 1
+
+ ::continue::
+ end
+
+ for directory, lines in pairs(directories) do
+ for _, filename in ipairs(lines) do
+ if filename:match(":") or
+ directories[file.join(directory, filename)]
+ then
+ goto continue
+ end
+
+ files[filename] = directory
+ n_files = n_files + 1
+
+ if filename:match("%u") then
+ remap[filename:lower()] = filename
+ n_remap = n_remap + 1
+ end
+
+ ::continue::
+ end
+ end
+ --]]
+
+ local files, remap = { }, { }
+ local n_files, n_remap, n_directories = 0, 0, 0
+ local sections = content:split("\n\n")
+ for _, section in ipairs(sections) do
+ if section:match("^%%") then
+ goto continue_outer
+ end
+ local lines = section:split("\n")
+ local base = lines[1]:sub(3, -2)
+ n_directories = n_directories + 1
+
+ for _, filename in ipairs(lines) do
+ if filename:match(":") then
+ goto continue_inner
+ end
+
+ files[filename] = base
+ n_files = n_files + 1
+
+ if filename:match("%u") then
+ remap[filename:lower()] = filename
+ n_remap = n_remap + 1
+ end
+
+ ::continue_inner::
+ end
+ ::continue_outer::
+ end
+
+ return {
+ files = files,
+ remap = remap,
+ metadata = {
+ directories = n_directories,
+ files = n_files,
+ remappings = n_remap,
+ path = path,
+ }
+ }
+end
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua
index ea7954d..b4af471 100644
--- a/scripts/context/lua/mtxrun.lua
+++ b/scripts/context/lua/mtxrun.lua
@@ -27075,6 +27200,7 @@ local ownlibs = { -- order can be made better
'data-aux.lua', -- updater
'data-tmf.lua',
'data-lst.lua',
+ 'data-tld.lua', -- TeX Live
'libs-ini.lua',
@@ -27105,6 +27231,9 @@ local ownlist = {
owntree .. "/../../../texmf-local/tex/context/base",
owntree .. "/../../../texmf-context/tex/context/base",
owntree .. "/../../../texmf/tex/context/base",
+ -- TeX Live
+ owntree .. "/../../texmf-dist/tex/context/base",
+ owntree .. "/../../texmf-dist/tex/context/base/mkiv",
}
if ownpath == "." then table.remove(ownlist,1) end
diff --git a/tex/context/base/mkiv/luat-lib.mkiv
b/tex/context/base/mkiv/luat-lib.mkiv
index e07a2d8..1cd0e3d 100644
--- a/tex/context/base/mkiv/luat-lib.mkiv
+++ b/tex/context/base/mkiv/luat-lib.mkiv
@@ -71,6 +71,7 @@
\registerctxluafile{data-con}{}
\registerctxluafile{data-use}{}
\registerctxluafile{data-aux}{}
+\registerctxluafile{data-tld}{}
\registerctxluafile{luat-cbk}{}
\registerctxluafile{luat-run}{}
diff --git a/tex/context/base/mkxl/luat-lib.mkxl
b/tex/context/base/mkxl/luat-lib.mkxl
index 64128e6..35d3381 100644
--- a/tex/context/base/mkxl/luat-lib.mkxl
+++ b/tex/context/base/mkxl/luat-lib.mkxl
@@ -76,6 +76,7 @@
\registerctxluafile{data-con}{}
\registerctxluafile{data-use}{}
\registerctxluafile{data-aux}{}
+\registerctxluafile{data-tld}{}
\registerctxluafile{luat-cbk}{autosuffix}
\registerctxluafile{luat-run}{autosuffix}
<<attachment: lsr-modified-files.zip>>
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : [email protected] / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net ___________________________________________________________________________________
