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 an efficient drop-in Data replacement for AssocMap.Map #5929

Closed
Tracked by #5928
ana-pantilie opened this issue Apr 29, 2024 · 3 comments · Fixed by #5927
Closed
Tracked by #5928

Create an efficient drop-in Data replacement for AssocMap.Map #5929

ana-pantilie opened this issue Apr 29, 2024 · 3 comments · Fixed by #5927

Comments

@ana-pantilie
Copy link
Contributor

ana-pantilie commented Apr 29, 2024

From @zliu41 :

AsData doc: #5729

The goal is to create a Map for Plutus Tx that is encoded in BuiltinData. In contrast, PlutusTx.AssocMap wraps a regular list encoded in SOP.

Using AsData on PlutusTx.AssocMap won’t be effective, because it is backed by a regular (SOP-encoded) list, not a data-encoded list. If we simply wrap the PlutusTx.AssocMap.Map definition in AsData, it would become less, not more efficient, because two frequent operations, wrapping and unwrapping (via toList and fromList ) will be linear (converting an SOP list to or from Data).

Instead, we should implement all operations for the new Map type such that they do not involve regular lists.

I have an initial implementation but didn’t finish addressing all the comments: #5701 Please take it from there.

Once we are done with Map, we will be ready to wrap the ScriptContext types (for V1, V2 and V3) in AsData, which will significantly speed up scripts that only access a small portion of the script context.

@uhbif19
Copy link

uhbif19 commented Jun 6, 2024

Cannot asData encode "regular" lists with built-in lists as well? It seems like it should be always more performant this way.

@ana-pantilie
Copy link
Contributor Author

@uhbif19 The SOP list type is encoded as a builtin list in its data representation:

instance ToData a => ToData [a] where

Does this answer your question or did I misunderstand?

@uhbif19
Copy link

uhbif19 commented Jun 10, 2024

@ana-pantilie

You right, I formulate my question incorrectly.

This issue implements AssocMap encoded in BuiltinData. That way one can use AssocMap in asData datatypes. For same reason one needs List encoded in BuiltinData, to use lists in asData datatypes. Is that not correct?

I think that asData translation could change regular SOP-encoded lists to such BuiltinData-backed lists. But may be I am wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants