Skip to content

Array structural split/join allocates and copies (blk_half/blk_node); the paper says both halves come in place and joining is free #804

Closed

Description

@phenomenon0

What you did

Compared the runtime paper's array cost model with the emitter and runtime routines in the current tree (source reading only; no timing was measured).

What happened

The paper (bend2/docs/BendRT/main.typ, § Arrays): "A match on the tree takes both halves in place, and joining two adjacent halves back is free."

The emitter (bend2/comp.ts at 0b7e2b1): an Array ANode{l, r} constructor emits blk_node(e, l, r) (line 2228), and a match on ANode emits two blk_half(e, sw, hi) calls (line 2647). Those routines allocate and copy: blk_node (line 4068) allocates the merged block, copies both halves word by word, then frees both inputs; blk_half (line 4093) allocates and copies each half, then frees the source on the high call. The compiler's own comment (lines 4007-4016) states it: "A match on ANode is blk_half twice: each half allocated in its class and copied... ANode{l, r} is blk_node: the merged class, l and r copied and freed shallow... A match to the leaves copies O(n log n) words where a view copied none; get, set, swap, size and new open no half."

So for materialized structural split/join (indexed get/set opens no half), the paper's cost model does not match the implementation. Either the paper should say allocate-and-copy, or the views should be implemented.

bend --version

bend 2.0.5

uname -sm

Linux x86_64

Activity

  1. VictorTaelin commented on Sep 18, 2026

    @VictorTaelin
    Contributor

    The paper was stale: arrays copied on split/join since views were dropped (a view changed class on every split and leaked a slot per iteration). The BendRT paper now says a match copies each half into its own block and a node copies both back, O(n log n) words on a walk to the leaves; get, set and swap open no half. The PDF is rebuilt in the repo.

    Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.

  2. added a commit that references this issue on Sep 18, 2026
    babd023
  3. added a commit that references this issue on Sep 27, 2026
    ae2bcbf
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions