Skip to content

Use UArray instead of Set for builtin availability check#7736

Open
zeme-wana wants to merge 1 commit intomasterfrom
naughty-tesla-3c6207
Open

Use UArray instead of Set for builtin availability check#7736
zeme-wana wants to merge 1 commit intomasterfrom
naughty-tesla-3c6207

Conversation

@zeme-wana
Copy link
Copy Markdown
Collaborator

@zeme-wana zeme-wana commented Apr 23, 2026

Summary

Addresses the TODO in SerialisedScript.hs:202 suggesting a better data structure for the builtin availability check in scriptCBORDecoder.

Previously checkBuiltin did an O(log n) Set.member on a Set DefaultFun. DefaultFun already derives Ix, so a UArray DefaultFun Bool gives a true O(1) unboxed array index with no fromEnum/hash at the lookup site (GHC's Ix instance handles the offset).

The builtin availability check in `scriptCBORDecoder` was using
`Set DefaultFun` for O(log n) membership, with a TODO suggesting
`IntSet`. A `UArray DefaultFun Bool` is a better fit: since
`DefaultFun` derives `Ix`, lookup is a true O(1) unboxed array index
with no conversion at the lookup site.

The array is built once per call via `runSTUArray`, folding over the
`Set` through its `Foldable` instance (no intermediate list). The
array covers all ~100 `DefaultFun` constructors.
@zeme-wana zeme-wana self-assigned this Apr 23, 2026
@zeme-wana zeme-wana added the No Changelog Required Add this to skip the Changelog Check label Apr 23, 2026
@zliu41
Copy link
Copy Markdown
Member

zliu41 commented Apr 23, 2026

Unclear this is an improvement. Try validation-decode and validation-full benchmarks.

@zeme-wana zeme-wana requested review from Unisay and zliu41 April 23, 2026 13:56
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