Skip to content

lua: register tilemaker's functions before the profile is loaded - #1003

Open
dktue wants to merge 1 commit into
systemed:masterfrom
dktue:lua/register-before-profile
Open

dktue wants to merge 1 commit into
systemed:masterfrom
dktue:lua/register-before-profile

Conversation

@dktue

@dktue dktue commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Gain: a profile can keep tilemaker's functions in locals at its top (local Find, Holds, Layer = Find, Holds, Layer), which Lua reaches faster than globals. Until now such a profile failed with a Lua runtime error, because the functions were registered only after the profile had been loaded. Output is unchanged; I haven't timed how much the locals save, as that depends on the profile.

Follow-up to @cldellow's first question on #993, kept separate from it as promised there.

What

  • OsmLuaProcessing's constructor ran dofile on the profile first and then set Find, Layer, Attribute and the rest as Lua globals. The registrations move into a helper, registerLuaFunctions, which now runs before dofile.
  • It runs again after dofile, so a function the profile defines with the same name as one of tilemaker's is still replaced by tilemaker's, as before. Without this, such a function (dead code until now) would suddenly take effect. The helper is cheap, and it runs once per thread when the Lua state is set up.
  • docs/CONFIGURATION.md: one paragraph after init_function, on keeping the functions in locals.
  • The bundled profile is unchanged, as perf(lua): replay way_function and node_function from a memo; native MercatorArea and MinZoomByArea #993 rewrites it; once both are in, it can take the locals.

Output

Unchanged for any profile that worked before.

Verification

Linux, GCC 14, Boost 1.83, Lua 5.4, four extracts (Lake Huron, Canberra, Patagonia, Canary Islands), bundled profile, OpenMapTiles config without shapefile layers. Variants: master; this PR; this PR with a line of 13 locals at the top of the profile (local Find, Holds, Layer, … = Find, Holds, Layer, …); this PR with the profile's own Area() and Layer() appended.

  • Lake Huron, 1 thread: all four variants and a second master run give the same file (sha256 dbc759aa).
  • The other three extracts, 4 threads, .mbtiles, compared tile by tile with each layer's features taken as a multiset: master's output varies between runs (features with equal sort keys, and the bundled profile's pairs() in GetPOIRank), so a second master run is the control. Every variant differs from master only in the poi layer and by as much as master's own rerun (Canberra 118 tiles for master's rerun vs 129-151 for the variants, Canary 525 vs 529-568, Patagonia 209 vs 127-156). No other layer differs in any tile.
  • With master, the profile with the locals fails with a Lua runtime error, as expected.
  • Builds with CMake with 0 warnings. CI is the test for macOS and Windows.

🤖 Generated with Claude Code

The profile was run (dofile) before Find, Layer, Attribute and the other
functions were set as globals, so a profile could not keep them in locals
at its top. They are now registered before the profile is loaded, and
again afterwards, so that they still replace profile functions of the
same name, as before. CONFIGURATION.md mentions the locals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant