Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a prepareTxScripts function for profiling scripts #721

Merged
merged 5 commits into from
Feb 14, 2023

Conversation

ch1bo
Copy link
Member

@ch1bo ch1bo commented Feb 10, 2023

This gets ahold of all the applied plutus scripts in a transaction to profile them externally by returning the fully applied, flat-encoded UPLC programs.

This can be seen as the acquiring an executable script step of the plutus-tx profiling guide.

Thoughts when creating this and some usage tips are in the logbook.

With this profiles and flame-graphs of memory/cpu usage of our hydra scripts like this can be made:

image

Created a page in /benchmarks on our website, explaining steps to profile scripts in the hydra repository and link it from contribution guidelines.

Created an issue to re-expose mkTermToEvaluate in latest plutus version IntersectMBO/plutus#5133

@ch1bo ch1bo requested review from a user, v0d1ch and ffakenz February 10, 2023 15:04
@github-actions
Copy link

github-actions bot commented Feb 10, 2023

Transactions Costs

Sizes and execution budgets for Hydra protocol transactions. Note that unlisted parameters are currently using arbitrary values and results are not fully deterministic and comparable to previous runs.

Metadata
Generated at 2023-02-13 14:21:00.842196398 UTC
Max. memory units 14000000
Max. CPU units 10000000000
Max. tx size (kB) 16384

Script summary

Name Hash Size (Bytes)
νInitial 7bb44e248f92ae5d2c4c744244b469d59a5bfa8a5d8ce9b6b27e5750 5530
νCommit 70c545fc894ada81ad46715bac1a11fa755b3e3a1d94f03254a4d397 2473
νHead c1fa50bb6fb1b7f84f4b103bcfb6f71eaeb4de93ddcab99729c122fb 9928

Cost of Init Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 5048 9.94 3.92 0.48
2 5253 13.93 5.52 0.53
3 5458 15.21 5.99 0.56
5 5869 19.50 7.65 0.62
10 6893 28.74 11.20 0.77
46 14276 99.82 38.58 1.86

Cost of Commit Transaction

Currently only one UTxO per commit allowed (this is about to change soon)

UTxO Tx size % max Mem % max CPU Min fee ₳
1 633 20.95 8.45 0.41

Cost of CollectCom Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 13137 22.07 8.83 0.97
2 13559 37.72 15.25 1.16
3 13840 54.37 22.14 1.36
4 14262 75.56 30.95 1.61
5 14656 99.83 41.08 1.90

Cost of Close Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 10534 16.28 6.99 0.80
2 10733 18.42 8.22 0.83
3 10864 19.41 8.66 0.85
5 11228 22.86 10.63 0.91
10 12052 29.44 14.33 1.02
47 15133 63.02 29.34 1.54

Cost of Contest Transaction

Parties Tx size % max Mem % max CPU Min fee ₳
1 10571 21.44 8.95 0.85
2 10745 23.24 9.87 0.88
3 10901 24.49 10.57 0.90
5 11265 28.87 12.89 0.97
10 12081 37.49 17.32 1.11
35 16288 81.50 40.35 1.82

Cost of Abort Transaction

Some variation because of random mixture of still initial and already committed outputs.

Parties Tx size % max Mem % max CPU Min fee ₳
1 15092 28.55 12.07 1.13
2 15516 48.36 20.76 1.37
3 15343 57.45 24.33 1.46
4 15767 83.32 35.70 1.77

Cost of FanOut Transaction

Involves spending head output and burning head tokens. Uses ada-only UTxO for better comparability.

UTxO Tx size % max Mem % max CPU Min fee ₳
1 14780 10.10 4.40 0.91
2 14950 12.63 5.68 0.95
3 14987 14.16 6.56 0.97
5 14993 16.87 8.19 1.01
10 15304 25.26 12.89 1.12
20 15599 40.09 21.53 1.32
42 16323 73.60 40.90 1.76

@github-actions
Copy link

github-actions bot commented Feb 10, 2023

Test Results

285 tests  ±0   279 ✔️ ±0   18m 19s ⏱️ + 4m 54s
  97 suites ±0       6 💤 ±0 
    5 files   ±0       0 ±0 

Results for commit 996d9f0. ± Comparison against base commit dc6b3ef.

♻️ This comment has been updated with latest results.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document any hydra-specific steps needed for this? where?

that would be great, I think the documentation would be a good place for that. In general, we should move all the technical stuff that's in the wiki in the docs for more exposure and better tracking, this includes coding conventions, build guidelines, releases strategy, etc.

How to ensure these functions stay exposed at the ledger/plutus-core?

Not sure what you mean here, we don't have much control over the plutus or ledger codebase so if they decide to drop support in some future version, the best we can do is try to be warned in advance and yell.

Add another hydra-specific function to identify scripts by matching hashes from hydra-plutus?

That would be good but probably orthogonal to this PR's feature?

Something I would have added to this PR is calling this function from the inspect-scripts executable for all scripts we have. Perhaps even add a specific CI step to automatically generate a profile from saturated scripts?

@ch1bo
Copy link
Member Author

ch1bo commented Feb 10, 2023

calling this function from the inspect-scripts executable for all scripts we have

This is not possible as the scripts themselves are missing concrete datum, redeemer, and script context arguments. To profile scripts we need all of them. Hence, this function which extracts them from the Tx.

@ghost
Copy link

ghost commented Feb 10, 2023

calling this function from the inspect-scripts executable for all scripts we have

This is not possible as the scripts themselves are missing concrete datum, redeemer, and script context arguments. To profile scripts we need all of them. Hence, this function which extracts them from the Tx.

I know, but what prevents us from constructing a "Healthy Tx" and extract the fully applied scripts from this tx?

@ch1bo
Copy link
Member Author

ch1bo commented Feb 13, 2023

I know, but what prevents us from constructing a "Healthy Tx" and extract the fully applied scripts from this tx?

That would be possible, but we would need to put something like that into the hydra-node package. Definitely out of scope for this PR I'd say though.

@ghost
Copy link

ghost commented Feb 13, 2023

Definitely out of scope for this PR I'd say though.
Yes!

@ch1bo ch1bo force-pushed the ch1bo/prepare-tx-scripts branch from 3d147a5 to c157418 Compare February 13, 2023 12:20
@ch1bo ch1bo force-pushed the ch1bo/prepare-tx-scripts branch from e1ec0af to 996d9f0 Compare February 13, 2023 14:06
@ch1bo ch1bo requested a review from a user February 13, 2023 14:11
Copy link
Contributor

@v0d1ch v0d1ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@ch1bo ch1bo merged commit 1c4c2aa into master Feb 14, 2023
@ch1bo ch1bo deleted the ch1bo/prepare-tx-scripts branch February 14, 2023 08:17
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor suggestions, feel free to ignore.


# Profiling Hydra scripts

This is a quick tutorial how to profile Hydra scripts and is intended for
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos:

  • a quick tutorial -> a quick tutorial on
  • and is intended -> , and it is intended

This is a quick tutorial how to profile Hydra scripts and is intended for
contributors to the `hydra-node`.

On every PR and also for the latest `master`, we do compute typical transaction
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: remove transaction

-- [...]
```

After running the corresponding code (`tx-cost` in our example), we will be left
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

running tx-cost executable in our example


Unfortunately it's quite hard to tell them apart, but script sizes should help
in telling the big `vHead` script apart from the smaller `vCommit` script. In
the profile, names of original `plutus-tx` functions will be retained so that
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: so that -> which

Unfortunately it's quite hard to tell them apart, but script sizes should help
in telling the big `vHead` script apart from the smaller `vCommit` script. In
the profile, names of original `plutus-tx` functions will be retained so that
should make it clear at the latest.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: at the latest -> which is which?

upstream projects and use your distribution's package manager):

```
nix shell nixpkgs#flamegraph github:input-output-hk/plutus#x86_64-linux.plutus.library.plutus-project-924.hsPkgs.plutus-core.components.exes.traceToStacks github:input-output-hk/plutus#x86_64-linux.plutus.library.plutus-project-924.hsPkgs.plutus-core.components.exes.uplc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why 924? Are we not still using ghc 8.10.7?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plutus is already supporting 9.2.4 and their nix environment is parameterized by it.

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.

2 participants