Repository navigation
Description
Tracks the measurement that decides whether str gets an O(1) copy. No representation change happens under this issue; it produces numbers.
Context
Ruling (Eric, 2026-09-19): a copy is never implicit unless it is O(1). str is an owned (ptr, len) heap buffer today; §15.2 says &str → str is .to_owned() (allocates). So an owned-value demand on a &str view is spelled .clone() everywhere, comprehensions included ("option A"; landed with the fix for the slice/array double owner). That holds regardless of what happens here.
Reference survey (verified in .reference/): none of go / mojo / rust / scala3 / swift / Vale / zig copies a string implicitly while paying an allocation for it. The ones with implicit copy made the copy O(1) first — Mojo (3-word copy + relaxed-atomic refcount, COW, ≤23 B inline; stdlib/std/collections/string/string.mojo:601-613), Swift (2 words + ARC retain, skipped for small/immortal strings), Vale (str is always ShareT; alias + RC++, nothing in an immutable region; Backend/src/region/rcimm/rcimm.cpp:99-114). Rust, whose String::clone allocates, spells it. Mojo 0.25.6 drew the line exactly here: List/Dict/Set lost implicit copy, String kept it.
B1, the candidate
Immutable shared str with a refcount:
strstays(ptr, len); the count lives in the allocation header the allocator already writes before the payload.- Static literals are immortal, marked in the value itself (a bit in
len), so copying or dropping one touches nothing. - Copy = increment; drop = decrement, free at zero.
++keeps its in-place append only when the count is 1 (str_owned_capacity_from_ptr). - Strings hold no pointers: no cycles, no leak risk.
- The run-time "is this pointer heap-owned?" lookup (
rt_payload_start_is_owned, a binary search of the allocator's range table on every string free and capacity check) goes away.
What to measure, on stage1 self-compiling the compiler (with-stage1 check src/main.w and a :dev build)
strclones — count and bytes copied (with_str_clone_refand the codegen clone path). This is what B1 turns into increments.strdrops — count, split static vs heap-owned. This is what B1 turns into decrements.- Cost of
rt_payload_start_is_ownedtoday — calls and time. In asampleprofile of c_import on 2026-09-18 it was the top frame (9,146 of ~21,000 samples). - Thread crossing — how many
strvalues cross a thread or fiber-scheduler boundary (spawn captures, channel sends). Decides atomic vs non-atomic counts, or an atomic count only for strings that areSend-ed. - Increment cost — a micro-benchmark of plain vs relaxed-atomic increment/decrement at the clone/drop rates from 1–2, on darwin-arm64 and linux-x86_64.
- In-place append — how often
++reuses capacity today, and how often the buffer would have been shared (count > 1) under B1.
Instrument inside the runtime (counters dumped at exit under an env var), not around the tools.
Decision rule (Eric)
- Numbers fine — thread crossing is rare or relaxed-atomic is cheap, and dropping
rt_payload_start_is_ownedpays for the increments → B1 becomes its own campaign. When it lands:strgets the cheap-copy capability, D22 extends by one line (a&strmaterializes astr), and the.clone()calls option A added on strings become redundant and are removed. - Numbers bad → A is the permanent answer, and the §13.6 examples change to iterate
move tokens.
Out of scope here
The representation change itself, small-string inline storage, and any spec wording. §13.6's examples do not compile as written under A; that edit is separate and needs Eric's blessed words.
Activity
Make main green: four tests and the spec inventory after #1205–#1208;…
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): superseded by D111 (Eric, 2026-10-08), which decided the representation this measurement was to inform: "stris a value: passing astralways copies … The implementation is an immutable, shared, reference-counted buffer (atomic count —strisSend; literals immortal): a copy is a pointer plus a count increment". D120 (the copy-on-write campaign) landed it.