IntersectMBO / IntersectMBO/plutus

Write a check to see if tail-recursive functions in PLC use flat memory

Open
#6,109 1 comment 0 reactions 0 assignees View on GitHub
Evaluation Low priority status: triaged tech debt Test
Dominant language
Haskell
Stars
1.6k
Forks
508
Avg merge
3d 10h
Merged PRs (30d)
22

Description

[weigh](https://hackage.haskell.org/package/weigh)

It would be nice to verify whether or not tail-recursive functions use constant memory or not. Kenneth has tried this before and thinks they do use constant memory, but it would be nice to check.

Possibly we can write something with weigh to test this. We couldn’t really make it a test since the results would be variable by machine etc., but we could at least make an executable that we can run from time to time to reassure ourselves.

One wrinkle is that weigh seems to measure allocations and we care about max memory really.

Discussion:


Michael Peyton Jones
September 30, 2022 at 12:23 PM

Believe me Serge, we know

Serge Kosyrev
September 29, 2022 at 10:05 PM

From the Plutus end user point of view, it doesn’t matter what the actual runtime memory cost is – the only thing that impacts them is the cost they pay.

Similarly, from a commercial perspective, what matters is the throughput of end-user smart-contract space units per block – as long as the service retains operation within safety margins.

So, if the Plutus cost model is pessimising the actual costs – that has a direct negative commercial impact.

Michael Peyton Jones
September 29, 2022 at 12:50 PM

[PLT-966: If it is safe, "free" memory for CEK machine frames when they are no longer on the stack](https://github.com/IntersectMBO/plutus/issues/6108)
for freeing the memory.

Michael Peyton Jones
September 29, 2022 at 12:36 PM

I think it’s absolutely expected that our costing says its linear in memory, since we never “free” memory for CEK machine frames. That’s something we could potentially improve. But this ticket is just about whether the real memory is flat or not.

Roman Kireev
September 29, 2022 at 12:23 AM

This script does not execute in constant space – the memory units it requires is proportional to the i

That’s what our Plutus costing machinery reports, but does the memory consumption actually grow as reported by htop or GHC profiling results?

Serge Kosyrev
September 29, 2022 at 12:00 AM

The script that is an exhibit of the problem is: https://github.com/input-output-hk/plutus-apps/blob/main/plutus-example/src/PlutusExample/Loop.hs
The key bits of that are: https://github.com/input-output-hk/plutus-apps/blob/main/plutus-example/src/PlutusExample/Loop.hs#L25-L36

This is supposed to be a dumb count-down loop – with recursion in a tail position:

loop i = if i == 1000000 then () else loop $ pred i

This script does not execute in constant space – the memory units it requires is proportional to the i

James Chapman
September 29, 2022 at 12:00 AM

I am interested in this as i harbouring the impression that it has a connection to environment pruning.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.