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

Rework the "Using Plutus Tx" section of the user guide #6516

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zliu41
Copy link
Member

@zliu41 zliu41 commented Sep 24, 2024

The section now looks like this:

Screenshot from 2024-09-24 11-24-38

  • "Optimizing scripts with asData": unmodified
  • "GHC Extensions, Flags and Pragmas": moved a small portion to "Differences From Haskell"
  • All other pages are written from scratch.

@effectfully
Copy link
Contributor

/benchmark validation

@effectfully
Copy link
Contributor

(sorry for hijacking)

Copy link
Contributor

Click here to check the status of your benchmark.

Copy link
Contributor

Comparing benchmark results of 'validation' on '24e3cfc0f' (base) and 'f93e076ef' (PR)

Results table
Script 24e3cfc f93e076 Change
auction_1-1 258.0 μs 182.3 μs -29.3%
auction_1-2 911.6 μs 645.9 μs -29.1%
auction_1-3 901.1 μs 901.7 μs +0.1%
auction_1-4 332.0 μs 270.0 μs -18.7%
auction_2-1 259.3 μs 182.8 μs -29.5%
auction_2-2 636.9 μs 643.8 μs +1.1%
auction_2-3 842.0 μs 843.2 μs +0.1%
auction_2-4 634.0 μs 632.6 μs -0.2%
auction_2-5 235.0 μs 235.4 μs +0.2%
crowdfunding-success-1 210.6 μs 210.8 μs +0.1%
crowdfunding-success-2 210.2 μs 211.1 μs +0.4%
crowdfunding-success-3 210.7 μs 301.1 μs +42.9%
currency-1 248.8 μs 357.7 μs +43.8%
escrow-redeem_1-1 346.7 μs 492.2 μs +42.0%
escrow-redeem_1-2 345.5 μs 493.2 μs +42.7%
escrow-redeem_2-1 413.2 μs 584.2 μs +41.4%
escrow-redeem_2-2 412.9 μs 582.3 μs +41.0%
escrow-redeem_2-3 412.8 μs 567.5 μs +37.5%
escrow-refund-1 156.7 μs 166.8 μs +6.4%
future-increase-margin-1 248.4 μs 254.3 μs +2.4%
future-increase-margin-2 540.2 μs 560.1 μs +3.7%
future-increase-margin-3 540.1 μs 540.2 μs +0.0%
future-increase-margin-4 494.3 μs 493.5 μs -0.2%
future-increase-margin-5 822.4 μs 1.177 ms +43.1%
future-pay-out-1 248.8 μs 251.6 μs +1.1%
future-pay-out-2 541.7 μs 538.0 μs -0.7%
future-pay-out-3 540.7 μs 539.7 μs -0.2%
future-pay-out-4 821.0 μs 819.4 μs -0.2%
future-settle-early-1 248.3 μs 249.6 μs +0.5%
future-settle-early-2 538.3 μs 539.9 μs +0.3%
future-settle-early-3 540.8 μs 541.8 μs +0.2%
future-settle-early-4 874.9 μs 616.7 μs -29.5%
game-sm-success_1-1 552.7 μs 397.6 μs -28.1%
game-sm-success_1-2 287.8 μs 221.9 μs -22.9%
game-sm-success_1-3 907.0 μs 629.1 μs -30.6%
game-sm-success_1-4 332.3 μs 234.2 μs -29.5%
game-sm-success_2-1 553.6 μs 508.6 μs -8.1%
game-sm-success_2-2 287.4 μs 286.7 μs -0.2%
game-sm-success_2-3 907.4 μs 905.9 μs -0.2%
game-sm-success_2-4 331.9 μs 332.4 μs +0.2%
game-sm-success_2-5 906.8 μs 917.7 μs +1.2%
game-sm-success_2-6 332.7 μs 332.8 μs +0.0%
multisig-sm-1 563.2 μs 563.9 μs +0.1%
multisig-sm-2 545.6 μs 545.7 μs +0.0%
multisig-sm-3 558.4 μs 559.5 μs +0.2%
multisig-sm-4 559.5 μs 389.8 μs -30.3%
multisig-sm-5 789.2 μs 664.9 μs -15.8%
multisig-sm-6 561.3 μs 396.4 μs -29.4%
multisig-sm-7 546.9 μs 384.1 μs -29.8%
multisig-sm-8 560.2 μs 394.0 μs -29.7%
multisig-sm-9 560.5 μs 456.9 μs -18.5%
multisig-sm-10 788.8 μs 788.1 μs -0.1%
ping-pong-1 471.4 μs 335.5 μs -28.8%
ping-pong-2 479.0 μs 349.2 μs -27.1%
ping-pong_2-1 285.2 μs 244.1 μs -14.4%
prism-1 239.7 μs 169.0 μs -29.5%
prism-2 583.1 μs 432.0 μs -25.9%
prism-3 392.6 μs 363.5 μs -7.4%
pubkey-1 203.2 μs 143.1 μs -29.6%
stablecoin_1-1 1.288 ms 927.3 μs -28.0%
stablecoin_1-2 280.3 μs 197.5 μs -29.5%
stablecoin_1-3 1.497 ms 1.055 ms -29.5%
stablecoin_1-4 296.0 μs 208.9 μs -29.4%
stablecoin_1-5 1.919 ms 1.345 ms -29.9%
stablecoin_1-6 365.5 μs 258.0 μs -29.4%
stablecoin_2-1 1.291 ms 911.9 μs -29.4%
stablecoin_2-2 280.0 μs 197.4 μs -29.5%
stablecoin_2-3 1.479 ms 1.048 ms -29.1%
stablecoin_2-4 296.2 μs 208.2 μs -29.7%
token-account-1 272.7 μs 192.6 μs -29.4%
token-account-2 482.7 μs 428.6 μs -11.2%
uniswap-1 589.6 μs 589.7 μs +0.0%
uniswap-2 314.8 μs 315.7 μs +0.3%
uniswap-3 2.488 ms 2.489 ms +0.0%
uniswap-4 478.8 μs 337.2 μs -29.6%
uniswap-5 1.653 ms 1.177 ms -28.8%
uniswap-6 457.0 μs 321.1 μs -29.7%
vesting-1 498.6 μs 351.1 μs -29.6%
24e3cfc f93e076 Change
TOTAL 45.29 ms 40.13 ms -11.4%

In general, we do not want GHC to perform optimizations, since GHC optimizes a program based on the assumption that it has non-strict semantics and is evaluated lazily (call by need), which is not true for Plutus Tx programs.
Therefore, `INLINEABLE` is preferred over `-fexpose-all-unfoldings`, even though the latter is simpler.
myPlutusTxCodeCompiled :: CompiledCode (Integer -> Integer)
myPlutusTxCodeCompiled = plc (Proxy @"location info") myPlutusTxCode
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe mention that "location info" is for debugging purposes and not very important


> ghc-options:
>
> : -fno-ignore-interface-pragmas
Copy link
Contributor

Choose a reason for hiding this comment

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

i think typo here with a leading :


In [`PlutusTx.Builtins.Internal`](https://plutus.cardano.intersectmbo.org/haddock/latest/plutus-tx/PlutusTx-Builtins-Internal.html), functions marked `OPAQUE` are directly converted to the corresponding builtin function.
For instance, `PlutusTx.Builtins.Internal.addInteger` is converted to UPLC term `(builtin addInteger)`.
Using the `OPAQUE` pramga prevents GHC from inlining these functions, allowing the Plutus Tx compiler to determine where exactly they are invoked, and compile them appropriately.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo "pragma"


## `IsString` Instances

[`IsString`](https://hackage.haskell.org/package/base/docs/Data-String.html#t:IsString) is a type class from `base`, and can be used along with the `OverloadedString` language extension to convert string literals to types other than `String`.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo "OverloadedStrings"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
No Changelog Required Add this to skip the Changelog Check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants