
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}

On 7/25/2025 5:03 AM, Max Chernoff via ntg-context wrote:
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.
I don't see the advantage of adding more code just for this purpose and even hard coding 'texlive' checks. On a tex live install that takes ages itself one 1 seconds doesn't save much. I've actually been thinking of filtering: only add files to the database that matter for context which leaves out complete subtrees. The file database isn't generated that often, it's access during a run that matters more.
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.
hm, i'll make a copy then (i tend to keep mkiv and mkxl separate as they can differ eventually, in fact there are still .lua files that will go .lmt because eventually mkiv will be like mkii: frozen) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------

Hi Hans, On Fri, 2025-07-25 at 08:54 +0200, Hans Hagen via ntg-context wrote:
I've actually been thinking of filtering: only add files to the database that matter for context which leaves out complete subtrees.
That seems like a good idea to me, and should also speed up the filename database generation by quite a bit.
The file database isn't generated that often, it's access during a run that matters more.
It depends---I update TeX Live every day, which means that the modification time on the ls-R files changes every day. TeX Live updates the "system" ConTeXt filename database (and formats) on every update, but since ConTeXt prefers the "user" filename database, running "context <filename>.tex" will take 15+ seconds to regenerate the filename database (and remake the formats) if it's the first time that I've run it that day. Not the end of the world, but annoying enough for me to write this patch :). A better solution would probably be to tell ConTeXt to always use the TL-managed databases (stored in $TEXMFVAR aka "$SELFAUTOPARENT/texmf-var/") for the TL files (stored in $TEXMFDIST aka "$SELFAUTOPARENT/texmf-dist/"), but I have no idea how to do that.
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.
hm, i'll make a copy then (i tend to keep mkiv and mkxl separate as they can differ eventually,
Works for me, thanks! Thanks, -- Max
participants (2)
-
Hans Hagen
-
Max Chernoff