Skip to content

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

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

Builtin Array example #7092

wants to merge 1 commit into from

Conversation

Unisay
Copy link
Contributor

@Unisay Unisay commented May 13, 2025

@Unisay Unisay self-assigned this May 13, 2025
@Unisay Unisay temporarily deployed to github-pages May 13, 2025 17:02 — with GitHub Actions Inactive
@Unisay Unisay changed the base branch from master to yura/run-compiled-code May 13, 2025 17:02
@Unisay Unisay added Do not merge No Changelog Required Add this to skip the Changelog Check labels May 13, 2025
@Unisay Unisay force-pushed the yura/run-compiled-code branch 4 times, most recently from e7bc91d to 0edc4ee Compare May 19, 2025 11:58
@Unisay Unisay force-pushed the yura/builtin-array-example branch from 3ce5ccf to 68761e8 Compare May 19, 2025 12:18
@Unisay Unisay temporarily deployed to github-pages May 19, 2025 12:18 — with GitHub Actions Inactive
@Unisay Unisay force-pushed the yura/run-compiled-code branch 6 times, most recently from 6022c7a to 310556f Compare May 26, 2025 08:54
@Unisay Unisay force-pushed the yura/run-compiled-code branch from 310556f to c575c94 Compare May 28, 2025 08:06
Base automatically changed from yura/run-compiled-code to master May 29, 2025 13:10
@Unisay Unisay force-pushed the yura/builtin-array-example branch from 68761e8 to f4e3f38 Compare July 4, 2025 13:40
@Unisay Unisay force-pushed the yura/builtin-array-example branch from f4e3f38 to 0f4f5c9 Compare July 4, 2025 13:46
@Unisay Unisay force-pushed the yura/builtin-array-example branch from 0f4f5c9 to 9c4bb4a Compare July 4, 2025 15:11
@Unisay Unisay temporarily deployed to github-pages July 4, 2025 15:11 — with GitHub Actions Inactive
@Unisay Unisay marked this pull request as ready for review July 4, 2025 15:12
@Unisay Unisay requested review from zliu41 and SeungheonOh July 4, 2025 15:13
Copy link
Contributor

github-actions bot commented Jul 4, 2025

PR Preview Action v1.6.2

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

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

@Unisay Unisay requested a review from zeme-wana July 7, 2025 09:02
@Unisay Unisay force-pushed the yura/builtin-array-example branch from 9c4bb4a to 5c3251c Compare July 10, 2025 09:41
Copy link
Member

@zliu41 zliu41 left a 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.
Copy link
Member

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.
Copy link
Member

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?

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.

2 participants