Title: LuaJIT blacklists loopified self-recursion while the loop body still allocates closures · Issue #204 · purescript-lua/purescript-lua · GitHub
Open Graph Title: LuaJIT blacklists loopified self-recursion while the loop body still allocates closures · Issue #204 · purescript-lua/purescript-lua
X Title: LuaJIT blacklists loopified self-recursion while the loop body still allocates closures · Issue #204 · purescript-lua/purescript-lua
Description: Problem Loopification (#181) lowers self-recursive tail calls to while true do loops. Under LuaJIT, in the current state of the performance series, this is a measured regression on the curried_step macro benchmark (n=2e6, medians from be...
Open Graph Description: Problem Loopification (#181) lowers self-recursive tail calls to while true do loops. Under LuaJIT, in the current state of the performance series, this is a measured regression on the curried_step...
X Description: Problem Loopification (#181) lowers self-recursive tail calls to while true do loops. Under LuaJIT, in the current state of the performance series, this is a measured regression on the curried_step...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/204
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"LuaJIT blacklists loopified self-recursion while the loop body still allocates closures","articleBody":"## Problem\n\nLoopification (#181) lowers self-recursive tail calls to `while true do` loops. Under LuaJIT, in the current state of the performance series, this is a measured regression on the `curried_step` macro benchmark (n=2e6, medians from `bench/tools/run_macro.lua`):\n\n| runtime | recursive worker (pre-#181) | loopified worker | ideal |\n|---|---|---|---|\n| PUC Lua 5.1 | 0.363s | 0.348s | 0.0075s |\n| LuaJIT | 0.196s | 0.366s | 0.0008s |\n\nPUC improves by the expected constant factor; LuaJIT gets ~1.9x slower.\n\n## Approach\n\nThis issue implements no optimisation of its own; it tracks a regression whose fix falls out of the rest of the series. The mechanism: the loop body still allocates closures on every iteration — `intAdd(acc)(n)` and `eqIntImpl(n)(0)` are curried foreign functions, so each iteration executes FNEW bytecodes. FNEW is NYI for the trace recorder, so every attempt to record the hot loop aborts, and the retry penalty ends in a blacklist. The accepted trace report (`bench/goldens/trace_curried_step.txt`) shows exactly this: the worker's blacklisted function entry (`IFUNCF`) is replaced by a blacklisted loop (`ILOOP`), while the small foreign closures keep their compiled `JFUNCF` traces.\n\nWhy the loop form is slower than the recursive form under the same FNEW aborts is not fully pinned down. The plausible reading: trace attempts and their abort/retry penalties are anchored differently (LOOP vs FUNCF sites), and the recursive shape happened to leave more of the per-iteration work inside compiled `JFUNCF` traces. The report's abort site set is unchanged, so the difference is in where the interpreter/compiled boundary falls, not in new abort causes.\n\n## Prerequisites / Relations\n\nThe FNEW sources inside loop bodies are exactly what the rest of the series removes: #178 (IR primops for the pure foreign subset), #180 (budgeted call-site inlining of dict methods), #186 (fork FFI audit for uncurried shapes). Blocked by those three. The loopification being measured landed in #181 (closed). Once a loopified body stops allocating per iteration, the loop is the shape the trace compiler wants, which is the point of #181.\n\n## Verification / Measurement\n\nRe-measure `curried_step` after each of #178 / #180 / #186 lands. Closes when the loop trace-compiles (`JLOOP` in the end state) and the LuaJIT number beats the pre-#181 baseline of 0.196s. If the tail of the series lands and the loop still blacklists, loopification needs a second look (for example a LuaJIT-aware veto while the body allocates).\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-07T19:49:09Z","url":"https://github.com/purescript-lua/purescript-lua/issues/204"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:04a7a487-94df-5201-10f9-5f2b78246fc3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA1A:2C4BED:67B7A9:85991B:6B00E055 |
| html-safe-nonce | 6acd162d71b62eb8cddd9ebe560bc5e1fa7b6da9a94a0fc7e13bd64bf1a7d5bb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTFBOjJDNEJFRDo2N0I3QTk6ODU5OTFCOjZCMDBFMDU1IiwidmlzaXRvcl9pZCI6IjExNDk2MDQwOTUxMzc0NzI1OTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fac0bb834d31bdd38e542356e95fb70ffe68baf44ed69e87d3d3a3ab867eb3e2 |
| hovercard-subject-tag | issue:4831725164 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/purescript-lua/purescript-lua/204/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e5b4acb4368704964a24d4e19e579ebebaaf637efeef7888ee5394bc47afd356/purescript-lua/purescript-lua/issues/204 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e5b4acb4368704964a24d4e19e579ebebaaf637efeef7888ee5394bc47afd356/purescript-lua/purescript-lua/issues/204 |
| og:image:alt | Problem Loopification (#181) lowers self-recursive tail calls to while true do loops. Under LuaJIT, in the current state of the performance series, this is a measured regression on the curried_step... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Unisay |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/purescript-lua/purescript-lua git https://github.com/purescript-lua/purescript-lua.git |
| octolytics-dimension-user_id | 131581790 |
| octolytics-dimension-user_login | purescript-lua |
| octolytics-dimension-repository_id | 587200487 |
| octolytics-dimension-repository_nwo | purescript-lua/purescript-lua |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 587200487 |
| octolytics-dimension-repository_network_root_nwo | purescript-lua/purescript-lua |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width