Skip to content

[0.31][Cost] Track abstraction-cost optimization and required design decisions #30

Closed

Description

@a19q3

Accepted decisions — 2026-09-21

D1–D6 are accepted in the tracked decision record. Implementation order: make rejection measurements observable; shorten wide immediates; coordinate exact-layout decoder sharing with private adapter frames; centralize scalar addressing and enable CFG-liveness slot reuse. Preserve the wire ABI and review each cost metric separately. No compiler changes or new optimization savings are claimed by this decision.

Full decision record — baseline: 8d6e200caa58d81429912df925a9322f691cb41d; research baseline remains 6d75a6e7. The choices below were the original open questions; this decision record now governs implementation. The issue stays open until its implementation acceptance passes.

Plan the next cost pass for 0.31, using branch 0.30 at 6d75a6e7e4ce55b940697428d895eda74a51ca86 as the starting baseline.

The three matched samples are already smaller and use fewer successful-execution cycles than their Rust references. The backend still has identifiable overhead: wide immediate expansion, repeated policy adapters, fixed entry buffers, argument copies, and conservative temporary storage. This work should reduce those costs while preserving the admitted behavior and the independently checked artifact boundary.

Baseline evidence: docs/CELLSCRIPT_COST_REGRESSION.md. The 0.30 samples are bounded evidence, not a claim of globally optimal code or universal superiority over hand-written Rust.

Work items

Decisions required for 0.31

The original proposals below are retained for context. The accepted D1–D6 decisions above and in the tracked record supersede them.

Decision Suggested starting point Required evidence
Optimisation objective and budgets Track ELF, successful/rejection cycles, witness bytes, and stack separately; require explicit byte/cycle tradeoffs Agreed corpus and per-fixture budgets
Wide-constant algorithm Deterministic sequence planning shared by sizing and emission, using existing instructions first Full-width value checks, branch relaxation, compiled execution
Policy decoder sharing and dispatch Evaluate exact-layout sharing; retain linear dispatch where its measured costs win Dense/sparse tags, mixed layouts, per-action worst path
Entry buffer ownership Right-size safe buffers first; evaluate borrowing only with explicit lifetime guarantees Nested calls, aliasing, outgoing arguments, checker mutations
Scalar storage Start with bounded liveness-based slot reuse CFG/call coverage and meaningful frame/traffic measurements
ABI and artifact compatibility Preserve wire ABI initially; version lowering/checker contracts when required Producer/consumer inventory and compatibility tests

Record each final decision in its owning issue or a linked tracked RFC, including alternatives, measurements, compatibility impact, and accepted limitations. Implementation PRs should identify who owns and reviews the affected backend/checker boundary.

Suggested order

  1. Agree metric definitions and budget policy; preserve the 0.30 baseline.
  2. Implement wide-immediate planning as the first bounded backend improvement.
  3. Decide the shared policy/entry adapter contract, then implement adapter sharing and frame/copy changes in coordinated steps.
  4. Add scalar-slot reuse after storage ownership is explicit.
  5. Rerun the full corpus and relevant gates on the final implementation commit, then set reviewed 0.31 budgets.

Measurement work continues throughout; the complete expanded corpus need not block the first local experiment.

Completion

  • All six design decisions are recorded with their research evidence and explicit evidence limits.
  • Every child issue is completed, or has an explicit deferral with reason and a new target; unchecked work is not described as shipped.
  • The final report compares identical fixtures/build profiles against the baseline, includes regressions and rejection paths, and distinguishes instruction-byte savings from whole-ELF savings.
  • Backend changes pass ./scripts/cellscript_gate.sh backend; merge-readiness is supported by ./scripts/cellscript_gate.sh ci on the actual final commit.
  • Checker independence, fail-closed behavior, and the four-file artifact bundle remain enforced.
  • Document remaining cost limits and publish reviewed static budgets.

This milestone plans 0.31 work. It does not reopen the accepted 0.30 capability boundary, bump package/toolchain versions, or authorize release publication. Compressed instructions, wire-envelope redesign, and a full general-purpose register allocator are outside this initial scope; any addition needs a concrete measured case and a separate decision.

Activity

  1. added this to the 0.31 milestone on Sep 21, 2026
  2. a19q3 commented on Sep 21, 2026

    @a19q3
    CollaboratorAuthor

    Research notes, 2026-09-21. CellScript source checked at 6d75a6e7. These are proposed experiments and decisions, not implementation results.

    The research adds two prerequisites and one useful ordering constraint to this plan.

    The immediate experiment reconstructed 231,462 inputs/checks in an independent host bit-vector model, with no mismatch and at most eight instructions observed. This is encouraging algorithm evidence, not a backend test or a full-domain bound. Its reproducible script and limitations are in the #31 research comment.

    For policy/ABI work, keep three experiments separate: shared decoders, tag routing, and argument ownership. A policy with common checks currently does two tag scans; the witness path has two different copy operations. Each has different semantics and checker requirements. The supported 64-action limit also deserves measurements beyond the current eight-action corpus.

    Proposed decision checkpoints

    Checkpoint Evidence needed to choose
    Measurement contract Distinguish transaction/group cycles, unavailable failures, individual frames and call-chain stack use
    Immediate plan Actual encoded-byte execution, size/layout agreement, unchanged 20-byte trampoline
    Adapter ownership Accepted witness set, parent lifetime, outgoing-stack isolation, independent checker contract
    Sharing/dispatch Component sizes and all-action/rejection costs for 1–64 variants, before/after immediate improvement
    Scalar slots Centralized addressing, CFG liveness, interference cases, 2,047-byte addressing boundary
    Acceptance A/B measurements with identical fixtures and pinned tools; explicit byte/cycle tradeoffs and fresh gates

    I would keep the initial witness wire ABI unchanged and judge candidates by separate byte, cycle and stack results. Prefer changes that improve one metric without worsening the others; when that is impossible, record the affected fixtures and why the tradeoff is acceptable. No universal percentage target is supported by the current evidence.

    The child comments link the relevant LLVM, RISC-V and CKB sources and propose concrete experiments. No compiler code was changed during this research, and the design decisions remain open.

    Research comments: #31 · #32 · #33 · #34 · #35.

  3. a19q3 commented on Sep 23, 2026

    @a19q3
    CollaboratorAuthor

    D1–D6 are implemented and pushed on 0.31 at 65df937f. The accepted decisions and implementation report describe the scope and compatibility boundary.

    The final clean commit's cost reports were compared against the retained pre-optimization baseline: 6,781 metric comparisons, no regressions, no changed fixture sources. The baseline retains its recorded dirty-source provenance; it is not relabeled as a clean historical commit.

    Sample ELF bytes Success cycles Static call-chain stack bound
    8 actions, 32-byte argument 11,680 → 8,048 14,158 → 13,189 11,472 → 6,160
    64 actions, 32-byte argument 73,440 → 43,592 29,822 → 22,299 11,472 → 6,160
    260 overlapping scalars 16,384 → 10,024 12,441 → 9,259 10,736 → 8,656

    Fresh acceptance recipes bind the regenerated ELF and derived Script hashes. Stale action, Lock, and missing-artifact mutations now fail preflight before the expensive node rebuild. The complete bounded replay passed all 43 actions, 17 Lock matrices and 26 stateful scenarios.

    Validation is complete for this implementation checkpoint: dev, the full local CI gate, GitHub CI on the final clean commit, and the full local backend gate passed. The backend run freshly rebuilt the pinned CKB node and passed production-mode local acceptance for all 43 actions, 17 Lock matrices and 26 stateful scenarios. This is local-node acceptance, not a new public-network deployment. The initial retry encountered the local /tmp quota; relocating the compiler cache through the supported CELLSCRIPT_CELLC_TARGET_DIR setting resolved it without changing source or weakening a gate.

    The final GitHub and local cost reports agree on all 88,204 compared numeric fields. Both bind clean 65df937f; the remote baseline comparison also passes all 6,781 checks.

    This is an implementation checkpoint, not a 0.31 release. Cargo versions remain 0.30.0. The named independent compiler/checker review, clean release replay and fresh downstream bundles remain release requirements; the 0.30 review waiver does not carry over. This issue and its children remain open for that acceptance work. No TAC was invoked.

  4. a19q3 commented on Sep 23, 2026

    @a19q3
    CollaboratorAuthor

    Remaining-work review, 2026-09-23, after the implementation checkpoint above.

    The five optimization implementations and their final backend/CI gates are complete at 65df937f. The remaining path is acceptance and release preparation. The original “no compiler changes” / “implementation planned” text and unchecked implementation tasks should be reconciled with the implementation report and final implementation and validation record, retaining their historical dates.

    Recommended order:

    1. Finish child acceptance. Name the independent compiler/checker reviewer, attach the review to this exact diff and resolve findings. Each child now has a specific review/evidence follow-up. In particular, [0.31][Backend] Reuse scalar stack slots and reduce temporary stack traffic #34 needs an explicit load/store-count statement, and [0.31][Cost] Extend cost budgets to rejection paths, composition, and call-chain stack use #35 needs a retrievable baseline source/report/comparison package. Do not repeat already accepted algorithm choices or regenerate budgets to make a new result pass.
    2. Separate the deferred experiments. Track observed stack peaks, alternative dispatch, borrowed/copy changes, and register/helper-scratch retention in distinct follow-ups. The recorded 0.32 target is a planning target, not a promise. None of [Language/Verifier][Research] Add typed zero-knowledge verifier contracts without a circuit DSL #22/[0.32][Language/ABI] Stabilize generic compatible-open Script and verifier handles #28/[0.32][ProtocolBundle] Stabilize runtime-selected open cross-Script roles #29 is part of this cost release.
    3. Prepare the actual 0.31 release boundary. Cargo currently remains 0.30.0 while native output uses lowering record v9. Coordinate compiler/checker/package/editor versions, compatibility notes, Registry consumers and source/bundle identities before distribution. Rebuild WASM and VSIX from the candidate and retain the metadata-only browser boundary. Update the candidate capability/business evidence rather than treating 0.30's accepted ledger as automatically valid for new ELFs.
    4. Run the full release gate on the final clean candidate. The passing backend run includes fresh pinned-node local acceptance, but it does not replace the complete release gate or a new public-network deployment. Compare each changed ELF/sidecar/deployment identity; 0.30's Pudge records remain evidence for their original bytes. If 0.31 claims deployment, obtain fresh matching deployment/readback evidence.
    5. Reconcile repository administration with the decision record. GitHub still reports main as default and retains older development branches, while the accepted branch decision names 0.31. The 0.31 CI workflow already covers pushes and the final successful run was a push run. Arrange the default-branch/rules change and any separately coordinated archived-branch cleanup; this review does not change or delete refs.

    The 0.30 independent-review waiver does not transfer. Close the cost tracker after child acceptance and its promised evidence are recorded; if release distribution continues separately, give it its own tracker and leave an explicit link rather than keeping optimization work ambiguously “unimplemented.”

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions