Skip to content

Refactor: make budget metrics and compiled code size metrics usable independently of each other; #7172

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

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

Conversation

Unisay
Copy link
Contributor

@Unisay Unisay commented Jun 30, 2025

Closes https://github.com/IntersectMBO/plutus-private/issues/1657

  • More specific function name: sizePlc -> countAstNodes
  • A function to count Flat-serialised bytes which could be re-used from multiple places: countFlatBytes.

Reworking the way the CompiledCode's Flat size is measured led to smaller sizes in many golden files.
I believe that current implementation is as close as possible to the PlutusLedgerApi.Common.serialiseCompiledCode.

@Unisay Unisay requested a review from SeungheonOh June 30, 2025 16:48
@Unisay Unisay self-assigned this Jun 30, 2025
Copy link
Contributor

github-actions bot commented Jun 30, 2025

PR Preview Action v1.6.1

🚀 View preview at
https://IntersectMBO.github.io/plutus/pr-preview/pr-7172/

Built to branch gh-pages at 2025-07-01 10:10 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@Unisay Unisay added No Changelog Required Add this to skip the Changelog Check and removed No Changelog Required Add this to skip the Changelog Check labels Jun 30, 2025
@Unisay Unisay force-pushed the yura/compiled-code-size branch from 5c769f5 to d5fe363 Compare July 1, 2025 09:56
@Unisay Unisay temporarily deployed to github-pages July 1, 2025 09:56 — with GitHub Actions Inactive
@@ -1,6 +1,6 @@
CPU: 218_533
Memory: 1_032
Term Size: 10
Flat Size: 37
Flat Size: 28
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have verified: Flat-serialised representation of this program takes 28 bytes:

58 1a 01 01 00 32 93 57 46 00 38 01 60 00 4b d6 08 14 12 0d 08 85 43 21 d1 08 94 51

@Unisay Unisay requested a review from effectfully July 1, 2025 09:59
@Unisay Unisay force-pushed the yura/compiled-code-size branch from d5fe363 to 9d9fcbd Compare July 1, 2025 10:07
@Unisay Unisay temporarily deployed to github-pages July 1, 2025 10:07 — with GitHub Actions Inactive
uplc <- toUPlc compiledCode
let
termSize = UPLC.programSize uplc
flatSize = UPLC.serialisedSize $ UPLC.UnrestrictedProgram uplc
Copy link
Collaborator

Choose a reason for hiding this comment

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

here type of uplc is UPLC.Program TPLC.Name uni fun () which will naturally have a different size of flat encoding

countFlatBytes :: CompiledCode ann -> Integer
countFlatBytes =
fromIntegral . BS.length . \case
SerializedCode plcBytes _pir _ -> plcBytes
Copy link
Collaborator

@SeungheonOh SeungheonOh Jul 1, 2025

Choose a reason for hiding this comment

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

plcBytes is flat encoding of UPLC.Program UPLC.NamedDeBruijn uni fun SrcSpans

import UntypedPlutusCore qualified as UPLC
import UntypedPlutusCore.Evaluation.Machine.Cek as Cek

type Term = UPLC.Term PLC.NamedDeBruijn DefaultUni DefaultFun ()
type Program = UPLC.Program PLC.NamedDeBruijn DefaultUni DefaultFun ()

-- | The size of a 'CompiledCodeIn' as measured in Flat bytes.
countFlatBytes :: CompiledCode ann -> Integer
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can go do PlutusTx.Code as well

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