Skip to content

lbt-plutus-plutustx: split Plinth splices into sublibraries (20 GB → 9.4 GB) - #301

Open
Benjmhart wants to merge 1 commit into
sean/plutustx-compiler-blowupfrom
sean-blowup-fix
Open

Benjmhart wants to merge 1 commit into
sean/plutustx-compiler-blowupfrom
sean-blowup-fix

Conversation

@Benjmhart

Copy link
Copy Markdown
Member

Fixes the memory blow-up when compiling the lbt-plutus-plutustx test suite. Nothing on this branch was actually broken: all 30 checks pass on a machine with 64 GB of RAM. The failure only happens when the machine runs out of memory compiling the test suite.

Where the memory goes

All figures are peak RSS on GHC 9.12.1, measured on a 64 GB box.

What was compiled GHC peak
Whole test module, as on this branch 20.2 GB (19.6 without -ddump-splices)
Any single splice on its own 0.3–2.6 GB. Largest: TxInfo/ScriptContext for V1–V3
First 35 splices on their own 6.1 GB
Last 34 splices on their own 21 GB
V3 TxInfo/ScriptContext group (5 splices) 8.6 GB, roughly the sum of its five splices
fooE on its own >62 GB, killed for running out of memory after 31 min
  • Memory adds up per splice. Each Plinth splice leaves a few GB of working memory live until the GHC process exits, so the peak is roughly the sum over every splice compiled in that process. The live heap peaks around 11 GB, and GHC's copying garbage collector roughly doubles that.
  • Splitting the module doesn't help. Every module of one component compiles in the same GHC process. Splitting into six modules within the test suite still peaked at 19.3 GB.
  • Tuning GHC's runtime doesn't help either. A compacting collector gave 20 GB. Heap caps of 8, 11 and 13 GB all fail with heap overflow.
  • -ddump-splices has no effect on memory.
  • fooE explains the "Compiling this causes an OOM" comment, but not the 20 GB. fooE (E is a product type with about 30 ledger-type fields) is unexported, so GHC drops it before Plinth ever compiles it. fooFInt and fooGInt are the same: unexported, and Plinth can't compile them anyway ("Unsupported construct: Mutually recursive datatypes").

Fix

  • Separate GHC processes for the splices. The splices move into three internal libraries, splices-a, splices-b and splices-c. Each library compiles in its own GHC process. Each depends on the one before it, so cabal and Nix build them one after another instead of in parallel, where their peaks would stack.
  • Same names for the tests. Test.LambdaBuffers.Runtime.PlutusTx.PlutusTx re-exports the same names as before, so the tests themselves don't change.
  • Cleanup. Deleted fooE, fooFInt and fooGInt, which were dead and can't be compiled. Removed -ddump-splices.

Peak GHC RSS drops from 20.2 GB to 9.4 GB, and the whole machine peaks at 10.3 GB.

Verified

All of this was built on a 64 GB Hetzner box from this branch's derivations:

  • All 30 checks.x86_64-linux pass, including pre-commit.
  • lbt-plutus-plutustx: all 383 tests pass.

Not addressed

  • Prelude.Array. No .lbf file uses it yet. In PlutusTx it is newtype Array a = Array a, a single element rather than a list, and its derived Eq is Haskell's Eq, not PlutusTx's. Using it in a schema would probably need both fixed.
  • Splices still need a few GB each. Adding many more heavy ledger-type splices to one library would bring the problem back. The fix then is a fourth library.

🤖 Generated with Claude Code

https://claude.ai/code/session_018RYHrLvKaySdv9c2pzbW3G

The test module compiled ~70 Plinth splices in one GHC process. Plinth's
per-splice working memory stays live until the process exits, so the peak is
roughly the sum over all splices: ~20 GB RSS (~11 GB live heap; GHC 9.12).
Splitting into modules inside one component doesn't help (same process).

Move the splices into three internal libraries (splices-a/b/c), each its own
GHC process; each depends on the previous so they build one after another.
Peak GHC RSS drops from 20.2 GB to 9.4 GB. Test.LambdaBuffers.Runtime.PlutusTx.PlutusTx
re-exports the same names, so the tests are unchanged (383 pass).

Also:
- drop fooE/fooFInt/fooGInt: unexported and never compiled. Compiled on its
  own, fooE (a ~30-field product of ledger types) exceeds 62 GB and is
  OOM-killed after 31 min; fooFInt/fooGInt fail with "Unsupported construct:
  Mutually recursive datatypes".
- drop -ddump-splices (debug output; no effect on memory, 19.4 vs 19.6 GB).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018RYHrLvKaySdv9c2pzbW3G

This branch has not been deployed

No deployments
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