-
Notifications
You must be signed in to change notification settings - Fork 479
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
Script context conversion is expensive #4209
Comments
Yeah, we know. The reason we do it this way is that it means that the ledger interface only operates with builtin types, rather than having to leak details of how datatypes are compiled into the interface with the ledger. We didn't expect that it would end up being so significant. I have a few ideas to improve this, but they mostly involve drastic changes, e.g. reintroducing sums and products into PLC so we can give a more stable format for datatypes that we're willing to commit to. |
The conversion is also heavy in terms of script size so there is much motivation to improve.
This sounds like a lot of work though... I've added a mention to #4174. Hopefully, someone will pick it up and help complete it eventually. |
I was asked by @jmchapman to share an idea I and some other folks developed, see https://gitlab.com/fresheyeball/plutus-tx-spooky. I haven't actually tested the above code, so I don't know if it works, but the idea is to lazily decode the newtype Spooky a = Spooky BuiltinData -- constructor is not exported
unSpooky :: UnsafeFromData a => Spooky a -> a
unSpooky (Spooky a) = unsafeFromBuiltinData a
toSpooky :: ToData a => a -> Spooky a
toSpooky = Spooky . toBuiltinData
-- example code
data SpookyScriptPurpose' = SpookyMinting (Spooky CurrencySymbol) | SpookySpending (Spooky TxOutRef) | SpookyRewarding (Spooky StakingCredential) | SpookyCertifying (Spooky DCert)
type SpookyScriptPurpose = Spooky SpookyScriptPurpose' The arguments passed to the scripts would be "decoded" as a The reason I'm bringing this up, is that I don't see the point of introducing explicit support for sums and products when we already have Perhaps I'm missing something? |
That's basically the approach I tried in #4235, which is a bit more generic in that it delays any kind of computation, not just deserialization. The problem with that approach (and I think also with yours) is that it's easy for users to cause the deserialization work to happen multiple times, which is actually worse than today. For example, I used I think it could be viable to do things this way but it would require a lot of refactoring of the libraries to pass around the forced fields rather than
The point is to not do any conversion at all, but rather pass in the data in exactly the form that the program needs. |
I get that, however, what you're describing is slightly different from the optimal state of what I meant to describe. To access |
I don't think that's true. Why do you think it's true? Both of them call
I think what you're suggesting is to basically compile datatypes to Data as a backend. That would work, but be much slower than the current version. Native sums and products is the fast version of that, effectively. |
You're right, but
How would the design of sums and products be? Would you effectively add a statically sized heterogeneous list with O(1) indexing? I personally think that it would be best if the language was kept as simple as possible, which is why I think changing |
This is being addressed by the Sums-of-products CIP. I just added the "status: needs action from the team" label where the "action" is @michaelpj bringing SOP to production. |
Unfortunately, that didn't work out. We're looking into other options such as optimizing |
I don't understand why you don't just have a pragma for encoding some data types as Data |
@michaelpj is that what we're converging to? Do there exist any docs on how the |
That's more or less what we're getting to, yes. I've got a ticket to write some docs for |
There's now @zliu41 do we have user-facing documentation on
Was done long ago: https://plutus.cardano.intersectmbo.org/docs/using-plutus-tx/optimizing-scripts-with-asData I'm closing this issue, because the original question was answered by Michael:
If there's still something unresolved here, we should open more focused issues, this one served us well for the general discussion and it's time to close it. |
Converting from
BuiltinData
toScriptContext
is pricy for large transactions. I don't see any obvious reason not to provide the script with theScriptContext
directly. Unlike the datum and redeemer, this has a known, fixed format.The text was updated successfully, but these errors were encountered: