-
Notifications
You must be signed in to change notification settings - Fork 483
Builtin Array example #7092
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
base: master
Are you sure you want to change the base?
Builtin Array example #7092
Conversation
e7bc91d
to
0edc4ee
Compare
3ce5ccf
to
68761e8
Compare
6022c7a
to
310556f
Compare
310556f
to
c575c94
Compare
68761e8
to
f4e3f38
Compare
f4e3f38
to
0f4f5c9
Compare
0f4f5c9
to
9c4bb4a
Compare
|
9c4bb4a
to
5c3251c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be clarified that this is an upcoming feature - not usable yet. And I think it deserves more publicity than being a part of "Other Optimization Techniques".
I suggest creating a category of pages, called "Upcoming Features". Under it, add a page called "Builtin Arrays", and put the content there. You can reference it in "Other Optimization Techniques".
|
||
For instance, a single lookup at index 99 of a 100-element list demonstrates this trade-off: | ||
* **Lookup Cost:** The CPU cost for the lookup on a standard Plinth list (a sum-of-products type) is 206 times higher than on a `BuiltinArray`. | ||
* **Creation Cost:** However, creating the `BuiltinArray` (by first creating a list and then converting it) is 11 times more expensive than creating the list alone. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? Creating a list is linear, creating an array is also linear, how can it be 11x worse?
Are you possibly trying to say: if you already have a list, then performing a single lookup is 11x faster than converting the entire list to an array, and then performing a single lookup?
|
||
For multiple lookups by index, converting a list to a `BuiltinArray` can be more cost-effective than performing lookups on the list directly. The initial cost of converting the list to an array can be offset by the significantly faster lookups. | ||
|
||
As a rule of thumb, if you only need to perform a single lookup, it is likely not worth the conversion cost. The benefits of using a `BuiltinArray` become apparent when you need to perform several lookups on the same data structure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is likely not worth the conversion cost.
What about picking list vs. array to use in the first place? If you use array in your data type in the first place, then you won't need the conversion. So should one generally prefer using array or list in the first place, and why?
Closes https://github.com/IntersectMBO/plutus-private/issues/1590
Preview: https://plutus.cardano.intersectmbo.org/pr-preview/pr-7092/working-with-scripts/other-optimization-techniques#using-builtinarray-for-index-based-lookups