Title: optimizeModule recomputes whole-module free-reference counts per binding · Issue #142 · purescript-lua/purescript-lua · GitHub
Open Graph Title: optimizeModule recomputes whole-module free-reference counts per binding · Issue #142 · purescript-lua/purescript-lua
X Title: optimizeModule recomputes whole-module free-reference counts per binding · Issue #142 · purescript-lua/purescript-lua
Description: Problem In optimizeModule (lib/Language/PureScript/Backend/IR/Optimizer.hs), withBinding decides whether a Standalone binding is used exactly once via uberModuleFreeRefs, which runs countFreeRefs over every expression in the module. That...
Open Graph Description: Problem In optimizeModule (lib/Language/PureScript/Backend/IR/Optimizer.hs), withBinding decides whether a Standalone binding is used exactly once via uberModuleFreeRefs, which runs countFreeRefs o...
X Description: Problem In optimizeModule (lib/Language/PureScript/Backend/IR/Optimizer.hs), withBinding decides whether a Standalone binding is used exactly once via uberModuleFreeRefs, which runs countFreeRefs o...
Opengraph URL: https://github.com/purescript-lua/purescript-lua/issues/142
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"optimizeModule recomputes whole-module free-reference counts per binding","articleBody":"## Problem\n\nIn `optimizeModule` (`lib/Language/PureScript/Backend/IR/Optimizer.hs`), `withBinding` decides whether a `Standalone` binding is used exactly once via `uberModuleFreeRefs`, which runs `countFreeRefs` over every expression in the module. That map is recomputed from scratch for each binding that reaches the `isUsedOnce` check, so a single `optimizeModule` run costs O(bindings × module size), and the whole thing re-runs on every `idempotently` iteration.\n\n## Approach\n\nCount free references once per `optimizeModule` run and update the counts incrementally as substitutions are applied. Each substitution's effect on the counts is known: the inlined expression's refs multiply by the number of substituted occurrences, and the substituted name's count drops to zero.\n\n## Prerequisites / Relations\n\nIndependent optimizer efficiency bug, found during the 2026-07-02 backend audit. The incremental-counting rework here is the basis that the fixes for #143 (stale-count use-once) and #167 (occurrence check in `betaReduce`) both build on.\n\n## Verification / Measurement\n\nThe whole-module free-reference map is computed once per `optimizeModule` run rather than once per `Standalone` binding that reaches the use-once check — reducing the cost from O(bindings × module size) to O(module size) per run. Confirmable by counting `countFreeRefs` invocations across a run.\n","author":{"url":"https://github.com/Unisay","@type":"Person","name":"Unisay"},"datePublished":"2026-07-02T18:17:34Z","url":"https://github.com/purescript-lua/purescript-lua/issues/142"}
| 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:da7001d2-918a-c903-8d5d-7275996c5a2c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8C8:A99C2:9A37AE:C8551A:6B00DFAE |
| html-safe-nonce | fe3443fc94ba04acdef4532e7c7ec8dec90d90db47395f1e33e80d446049065f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEM4OkE5OUMyOjlBMzdBRTpDODU1MUE6NkIwMERGQUUiLCJ2aXNpdG9yX2lkIjoiNjgxMDI1ODc4OTUzOTgzMTcyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6a040de3aadb235b28138ab8aa69166e0e0234e765bc64d8c351205410f8cf96 |
| hovercard-subject-tag | issue:4797137363 |
| 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/142/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5f780571c6c76c1c3e2b83b09b1622e978916797a18ee2802c8f031a61c890bd/purescript-lua/purescript-lua/issues/142 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5f780571c6c76c1c3e2b83b09b1622e978916797a18ee2802c8f031a61c890bd/purescript-lua/purescript-lua/issues/142 |
| og:image:alt | Problem In optimizeModule (lib/Language/PureScript/Backend/IR/Optimizer.hs), withBinding decides whether a Standalone binding is used exactly once via uberModuleFreeRefs, which runs countFreeRefs o... |
| 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