Skip to content

types: preserve sharing during structural lowering - #453

Open
tvolk131 wants to merge 1 commit into
BlockstreamResearch:masterfrom
tvolk131:perf/shared-type-lowering
Open

tvolk131 wants to merge 1 commit into
BlockstreamResearch:masterfrom
tvolk131:perf/shared-type-lowering

Conversation

@tvolk131

@tvolk131 tvolk131 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Shared aliases such as T0 = u8; Tn = (Tn-1, Tn-1) are stored as a compact graph, but structural lowering previously expanded them as a tree. This made type conversion, cast analysis, and compilation grow exponentially with alias depth.

Memoize completed subtype conversions by node identity within each conversion. Keep traversal iterative, and lower enum payloads through the same cache. Three regression tests check retained sharing, nested enum payload shapes, and 8,192 levels of nesting.

Validation

  • Before/after encoded program hashes match for p2pkh, HTLC, and kitchen-sink fixtures, each with debug symbols enabled and disabled.
  • Local release probe on a 466-byte, 18-level shared-alias program: analysis approximately 167 ms → 54 µs; compilation 336 ms → 90 µs. Best of three with allocation counting on an Apple M4 Pro; setup and output destruction excluded. These synthetic measurements demonstrate scaling rather than a general contract speedup.

Written with GPT 6.1 Sol on Extra High.

@tvolk131

Copy link
Copy Markdown
Contributor Author

Draft reminder: @tvolk131 needs to hand-review this change before undrafting it (marking it ready for review). Please keep this PR in draft until that hand review is complete.

@tvolk131
tvolk131 force-pushed the perf/shared-type-lowering branch from a690c32 to 8ae0eb4 Compare October 27, 2026 17:24
Written with GPT 6.1 Sol on Extra High.
@tvolk131
tvolk131 force-pushed the perf/shared-type-lowering branch from 8ae0eb4 to ece60c6 Compare October 29, 2026 03:24
@tvolk131
tvolk131 marked this pull request as ready for review October 29, 2026 03:43
@tvolk131
tvolk131 requested a review from delta1 as a code owner October 29, 2026 03:43

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant