Zero-copy and the residual flattens¶
Scope: this page describes the reference C++ implementation’s own copy behaviour — every
materialize / flatten call site in graph.cpp, rope.cpp, op_resolve_view.cpp,
op_resolve_walk.hpp, fwd_reply.cpp, fwd_router.cpp and the ESP-IDF WS integration, and
which of them are
structural. It is not the protocol standard; the implementation-independent ownership model is
reference 08 — views and ownership and
reference 09 — memory substrate. Its ESP-IDF / lwIP
references are integration facts about the transport seam.
Summary¶
On single-link traffic — one recv chunk becoming one ingress segment, which is what every
unfragmented TCP, UDP and WS producer emits — no payload flatten fires. rope_t::materialize
returns the sole link (core/include/libtracer/rope.hpp:rope_t::materialize), a refcount bump, so the branch
write, the field write, the per-node parse cache, span-only delivery and remote delivery
all resolve to reference counting rather than memcpy. Every payload flatten in the codebase is a
multi-link fallback.
Three copies are structural — they exist because of what the code must guarantee, not because a byte source is the wrong shape:
Structural copy |
Site |
Why it cannot go |
|---|---|---|
Ingress ownership |
|
A transient recv buffer cannot be borrowed by a rope that outlives the receive call |
Mutation ownership |
|
A mutated multi-link value must own a contiguous, patchable, trailer-cleared segment |
WS TX gather |
|
|
A fourth copy is bounded rather than structural: reply-route synthesis (tlv_sliced,
core/src/fwd_reply.hpp:emit_cursor_t::tlv_sliced) emits rewritten route wires — tens of bytes, never
payload-scaled.
The branch-write decode arena (core/src/graph.cpp:graph_t::write_branch) is structure storage, not a payload copy:
it backs the arena_tlv_t node array and the grammar walk stacks, whose existence is independent
of where the field bytes come from. The rope cursor is a byte source, so it does not remove the
arena; only a streaming decode does. Since #2879 the arena draws from the graph’s table source,
not a 4 KiB stack array, so it no longer sits on the receive task’s stack high-water.
1. Ownership invariant¶
The data plane copies each byte once, at the wire, into a refcounted owned segment; thereafter every view — routed suffix, child TLV, stored value, reply — is a refcount-bumped subview. The model itself is described implementation-independently in reference 08. What is specific to this implementation is where the mechanism lives:
Composition shares segments.
rope_t::subrope(off, len)(core/include/libtracer/rope.hpp:rope_t::subrope) trims the covering links withview_t::subviewand refcounts exactly the segments its window touches. Segment handles clone by a relaxed increment (core/include/libtracer/segment.hpp:if (seg_) seg_->refcount.inc_relaxed()); release is anacq_reldecrement that fires the backend’sdestroyat zero (core/include/libtracer/segment.hpp:segment_ptr_t::reset). Fan-out to N subscribers is N increments.Decode holds structure only.
decode_intoemitsarena_tlv_tnodes whosewire/bodyarestd::spaninto the caller’s input — “the arena holds structure only, never bytes” (core/include/libtracer/tlv_arena.hpp:only, never bytes, node type atcore/include/libtracer/tlv_arena.hpp:arena_tlv_t). Decode allocates node bookkeeping, never payload, and is zero-copy over its input provided that input is contiguous. That contiguity constraint is what §3 and §4 turn on.Egress scatter-gathers.
rope_t::to_iovec(core/include/libtracer/rope.hpp:to_iovec() const) emits one span per link into the original segments. The host WS server builds[header, link0, link1, …]andsendmsgs it with “no flatten, no re-copy (server frames are UNMASKED, RFC 6455 §5.1)” (core/src/transport_ws.cpp:ws_server_transport_t::send(std::span<const std::span<const std::byte>> iov)); TCP prepends a u32-LE length viaprefixed_iov_t(core/src/transport_tcp.cpp:prefixed_iov_t). WithkMaxServerIov = 16(core/src/transport_ws.cpp:constexpr std::size_t kMaxServerIov = kMaxInlineIov), the common reply (≤ ~6 spans) fits the stackstd::array<::iovec, kMaxServerIov + 1>(core/src/transport_ws.cpp:ws_server_transport_t::send(std::span<const std::span<const std::byte>> iov)) — zero heap, zero payload copy. The only host TX copy is the kernel skb copy every BSD socket pays.Flatten refuses a heterogeneous rope. A DEVICE link is not CPU-addressable, so a host memcpy would fault; the one body
flattenandtry_flattenshare checksall_host()up front and refuses (core/src/rope.cpp:rope_t::flatten_core). Since #917 the refusal carries its cause:try_flattenreturnsflatten_err_t::NOT_HOSThere andNO_MEMORYfor an allocator refusal, and a zero-length rope is a success carrying an empty view.flattenitself is the lossy wrapper that collapses all three back into that empty view.
2. Flatten call sites¶
Each row: the site, whether it fires on the single-link path (every unfragmented producer) or only on multi-link frames (fragmented WS, reassembled CAN), whether it is structural or a fallback, and whether the rope-cursor migration removes it. The circled numerals are row identifiers for the rest of this page.
# |
Site |
Single-link? |
Multi-link? |
Kind |
Removed by the rope cursor? |
|---|---|---|---|---|---|
① |
Ingress ownership — |
yes (it is the recv) |
yes |
Structural |
No — orthogonal; it is the ingress floor |
② |
Branch write — |
no — refcount bump |
yes (one flatten to feed the span cursor) |
Fallback |
Multi-link leg: yes, via a rope-native branch decode |
③ |
Field write — the twin of ② ( |
no — refcount bump |
yes |
Fallback |
Same as ② |
④ |
Branch-write decode arena, drawn from the table source since #2879 ( |
yes — paid on every branch write |
yes |
Structure scratch, not a payload copy |
No — see §3; the rope cursor is a byte source, not a structure store |
⑤ |
|
no — a single link is still COPIED, through the same backend ( |
yes — flattens the multi-link subrope |
Structural for mutated values |
No — this step is the ownership copy; it still owns |
⑥ |
Per-node parse contiguity — |
no — a single-link node adopts |
only per straddling node |
Fallback, span-node-shaped |
Yes — rope-native node accessors remove it |
⑦ |
|
no |
yes — only when no rope sink is installed; a refused materialize now DROPS the frame rather than handing the sink an empty span (#917) |
Fallback — the cost of a span-only sink |
Yes — installing the rope sink removes it; see §4.1 |
⑧ |
WS RX reassembly — RETIRED by #2483: each fragment is received into a segment and chained by the shared |
no — unfragmented delivers borrowed (scratch-backed, no per-frame alloc for fitting frames), or OWNING out of an injected bounded pool where an integrator named one (#1565, rank 2 below) |
no copy on an owning link (the fragments are chained); a borrowed link, and a fragmented credential, copy the completed message once |
— |
Closed |
⑨ |
WS TX gather — memcpy into a pooled tx work slot in |
copy per frame per peer; alloc only past the declared classes |
yes |
Structural within the |
No — TX-side; the cursor is irrelevant |
⑫ |
Reply-route synthesis — |
yes |
yes |
Bounded frame synthesis: the route wires are rewritten |
No — these are emitted bytes, not a copy of payload |
On the single-link path the only copies that fire are ① (the recv floor), ④ (the structure arena),
⑨ (the esp_http_server WS TX gather) and ⑫ (bounded route synthesis). ①, ⑨ and ⑫ are structural
or bounded, which leaves ④ as the one always-paid removable cost on that path — and it is not a
payload copy. Every payload flatten (②③⑤⑥⑦⑧) is multi-link-only. Completing the rope-cursor
migration is therefore insurance against fragmented-transport load, not a single-link win.
3. The branch-write decode arena¶
3.1 Two costs at one site¶
// graph_t::write_branch, core/src/graph.cpp
const std::expected<view_t, tr::view::flatten_err_t> head = // A: the flatten
value.try_materialize(*value_backend_);
head.error() == NO_MEMORY ? BACKPRESSURE : TYPE_MISMATCH // (paraphrased)
mem::block_source_t& src = *tables_; // B: the arena
wire::decode_into(head->bytes(), src);
Cost A, the flatten (core/src/graph.cpp:graph_t::write_branch) is zero-copy for a single-link rope — try_materialize returns
links()[0], a refcount bump (core/include/libtracer/rope.hpp:rope_t::materialize) — and memcpys only a
multi-link rope, drawing from the injected value_backend_. An exhausted pool is refused by name:
graph.cpp:graph_t::write_branch reads flatten_err_t::NO_MEMORY and surfaces BACKPRESSURE rather than letting
the decoder read an empty head back as a malformed value, and a DEVICE-link value — which no retry
makes CPU-decodable — takes the TYPE_MISMATCH arm instead. Before #917 both arrived as the same
empty view and the site had to guess from head.empty() && total_length() != 0. Because ingress
values are single-link until the rope-native branch decode lands, Cost A does not fire on
single-link traffic. It is a fallback.
Cost B, the arena (graph.cpp:graph_t::write_branch) is the storage behind decode_into’s node
array (std::pmr::vector<arena_tlv_t>) plus the grammar walk stack and the open-node stack. It is
structure-only scratch, drawn on every branch write regardless of link count. Until #2879 it was a
4 KiB stack array on the deepest thread, the httpd/WS receive task; it now draws from the graph’s
table source and is given back when the write returns.
sizeof(arena_tlv_t) is 48 bytes on an LP64 host (compiled against
core/include/libtracer/tlv_arena.hpp:arena_tlv_t; the two std::span members dominate at 16 bytes
each), so a tree’s draw grows with its node count. On a 32-bit target both spans halve and the node
is correspondingly smaller; that figure has not been compiled here and is not asserted.
3.2 Why the rope cursor does not remove the arena¶
rope_cursor_t (core/include/libtracer/rope_decode.hpp:rope_cursor_t) is a byte source. It lets the
grammar read fields off a scatter-gather rope by stitching straddling headers a byte at a time and
feeding the CRC link by link, satisfying the same Cursor concept as span_cursor_t. But
decode_into does not only read bytes — it stores structure: a random-accessible arena_tlv_t
array that parse_branch_node (core/src/graph.cpp:parse_branch_node) walks via end / first_child. That
node array is byte-source-independent. Swapping span_cursor_t for rope_cursor_t changes where field
bytes come from, not the fact that a node array and walk stacks must exist.
core/include/libtracer/rope_decode.hpp:SINK NOTE states the same constraint from the decoder’s side:
SINK NOTE: this validates STRUCTURE + CRC over a rope; it does not yet materialize a rope frame into a tlv_t / arena node, because both sink node types hold a borrowed contiguous std::span that cannot name a straddling payload (ADR-0041 §2). Producing sink nodes from a rope is the ratification-gated follow-on (the rope-aware-decode sink-type proposal).
So the arena and the flatten are two moves, not one:
A rope-native node type — the ratification-gated sink type of ADR-0052, rope-aware decode sink node type: convert
arena_tlv_t.wire/bodyfromstd::spanto an offset region{u32 off, u32 len}and haveparse_branch_nodeemitframe_rope.subrope(off, len). This removes Cost A for multi-link frames. The node array still exists and still needs backing storage.A streaming decode — a separate rewrite driving
parse_branch_nodeoffgrammar::walkpost-order callbacks (open / leaf / close), never materializing the node array. Only this removes Cost B.
The rope cursor is a precondition for move 1 and irrelevant to move 2.
3.3 Stack, not heap¶
Move 2 would not eliminate the RAM, and #2879 did not either: the node array and walk stacks must
live somewhere during decode. #2879 relocated them from a flat 4 KiB stack array — a
std::array reserves its whole frame slot whether filled or not — to the graph’s table source,
drawn only while a branch write runs. What dropped is the scarce stack high-water on the deep
receive task: write_branch’s own frame went from 4,800 B to 640 B (host GCC, -Os).
The other stack buffer on that task is frame ingress’s stack scratch
(core/include/libtracer/frame_ingress.hpp:frame_ingress_t::read, ADR-0087 §1): 1,152 B
(kIngressReadAheadBytes) on the stream servers’ poll thread and in the WS client’s receive
loop, and 256 B on the TCP dial loop, which reads no further than each prefix and uses it only to
read past a body the source refused. Every byte it takes is moved into its frame’s exact segment
before the read returns, so it holds nothing between reads. It is not a decode arena and carries
no structure, but it occupies the same frames. The WS client’s receive path is measured and
pinned per delivery arm by tools/esp_stack_gate.py (#2871), branch writes included (#2879).
That receive task is the binding constraint on a single-core, RAM-constrained node. In the ESP-IDF
WS integration, servicing a graph request in-call was measured overflowing an 8 KB stack and needing
~12 KB on the raw WS receive thread, against the 4 KB esp_http_server default; the integration
therefore sizes the task at kRequiredHttpdStack = 12288
(integrations/esp-idf/libtracer/include/libtracer_esp/httpd_ws_link.hpp:httpd_ws_link_t::kRequiredHttpdStack — a PUBLIC constant
since #955, because only the port-binding ctor can apply it and an adopting embedder must size the
task itself; the 8 KB the deep path was measured overflowing is the other half of the same
measurement, at integrations/esp-idf/libtracer/httpd_ws_link.cpp:kMeasuredOverflowStack, and the 4 KB platform
default is named at
integrations/esp-idf/libtracer/include/libtracer_esp/httpd_ws_link.hpp:the batch apply overflows the 4 KB httpd default). Against a 4096-byte
default the stack arena was a full half of the frame and the single largest consumer on the write
path, which is why #2879 moved it to the table source.
3.4 Arena exhaustion¶
The arena does not draw from a throwing upstream. core/src/graph.cpp:graph_t::write_branch draws from the
graph’s injected table source (core/include/libtracer/graph.hpp:graph_t::table_source), whose default is the
host slab pool over the platform heap, and exhaustion is a value. decode_into reports a
refused draw as TLV_NESTING_TOO_DEEP (“exceeds this receiver’s decode resources”, RFC-0006). A
refused draw for the decode, the root key, the plan or the sites answers BACKPRESSURE and is
counted once, as an out_of_memory delivery drop (#2879; the value flatten and vertex creation
are not counted there); a value the decode refuses for its shape stays
TYPE_MISMATCH and counts nothing. A bounded node that
injects its own table source gets the arena drawn from that store. No node-counting pre-pass exists, and none is
needed (#477, #588).
Streaming the decode (§3.2 move 2) changes where the walk stack is drawn from, not whether exhaustion is representable. The general failable-allocation contract is failable allocation and backpressure.
4. The rope cursor¶
4.1 Rope-native consumers¶
rope_cursor_t drives three live consumers with no flatten:
check_frameandvalidate_rope(core/src/rope_decode.cpp:check_frame,core/src/rope_decode.cpp:validate_rope) validate structure and CRC straight over a rope.The lazy
tlv_view_ttier walks children one header at a time off a refcounted subrope.The FWD request terminus:
resolve_terminus_rope(core/include/libtracer/fwd_router.hpp:fwd_router_t::resolve_terminus_rope) adopts a fragmented request astlv_view_t::over(rope)and resolves it throughop_resolver_t::resolve(tlv_view_t).
The forward hop scatter-gathers a multi-link frame over the rope cursor with no flatten; the egress
gathers each region’s per-link sub-spans into a block_array_t drawn from the injected rx_, and
exhaustion drops the frame rather than throwing (core/include/libtracer/fwd_router.hpp:The forward hop, read entirely by OFFSET,
#596).
Two limits on that tier are load-bearing. First, a single-link rope never reaches
resolve_terminus_rope — on_frame_rope_impl short-circuits it deliberately into the
single-link view path (core/src/fwd_router.cpp:fwd_router_t::on_frame_rope_impl, the check at core/src/fwd_router.cpp:if (frame.link_count() == 1)). Second, the tier earns its place only on large, lightly
fragmented frames: at 64 KB across 2 links it is ~12% ahead of flatten-then-arena, and behind it
everywhere smaller (core/include/libtracer/fwd_router.hpp:fwd_router_t::on_frame_impl, recorded as an erratum to
ADR-0053, lazy rope-backed decode view).
That figure carries no host, sample count or spread in the source that records it, so it is a
direction, not a budget.
Row ⑦ has changed shape rather than disappearing. The span fallback in
receiver_slot_t::deliver_rope (core/include/libtracer/receiver_slot.hpp:receiver_slot_t::deliver_rope) still exists for a
slot with no rope sink installed, but the router does not flatten on the reply path: a REPLY that
reaches its originator is handed to the sink rope-native
(core/src/fwd_router.cpp:fwd_router_t::on_frame_rope_impl). The contract at
core/include/libtracer/fwd_router.hpp:fwd_router_t::on_reply states it — the router performs no decode and no
flatten, a rope-delivered reply reaches the sink zero-copy, a sink that wants contiguous bytes
holds const view_t m = reply.materialize(), and only a multi-link reply pays one flatten, on
demand. The escape hatch is the consumer’s, not the router’s.
4.2 Sites the rope cursor does not reach¶
Rope-native branch and field decode (§3.2 move 1) — point the branch and field write paths at a rope-aware node type instead of
decode_into+materialize. Removes ②③.Streaming branch decode (§3.2 move 2) — removes ④’s node array (its draw from the table source; the stack array went with #2879).
Rope-native node accessors for the walk —
ensure_cache(core/src/op_resolve_view.cpp:wire().materialize(backend())) flattens each accessed node whose own subrope straddles a link. Convertingwire()/body()fromstd::spanto rope-native readers (fields viaload_le/for_each_span) plus a scatter-gather reply head removes ⑥.
None of these reaches ⑤. own_wire (core/src/op_resolve_view.cpp:view_node::own_wire) is structural: a mutated
multi-link value must own a contiguous, patchable, trailer-cleared segment
(ADR-0041, terminus arena decode span contract
§2), so it flattens once. The zero-copy pin_wire subrope applies only to the opt-in verbatim
referenced STORE, not to ops that patch bytes.
4.3 Complexity of a rope walk¶
span_cursor_t::byte_at is O(1). rope_cursor_t::byte_at calls locate(), a linear scan over links,
so load_le(n) is n such scans, a header read costs O(header_bytes × L) and a CRC feed costs
O(payload + L), for L links.
For a single-link rope — the common case, one recv chunk becoming one ingress segment, where
materializereturnslinks()[0]— L = 1, sorope_cursor_t≈span_cursor_tplus a trivial constant. There is no regression.For a multi-link rope the header pointer-chase is bounded by fragment count × a 4–6-byte header, and the payload feed is asymptotically identical to the memcpy it replaces, but read-only and without allocating a destination.
Against the alternative it removes —
flatten()is O(payload) read and write, plus a pool or stack allocation — the rope walk wins on latency (no write pass, no allocation) and on RAM (no destination buffer).
There is no latency-versus-RAM trade-off for the decode walk. The one genuine cost is code size:
rope_cursor_t lives in a separate translation unit so a span-only target never instantiates it
(ADR-0048, one wire grammar, chunk cursor, rope-aware decode
§1). That is a build-configuration trait, not a runtime trade-off.
5. The ingress copy¶
The ingress ownership copy (①) is structural as a copy, but it is not always an extra copy.
Why it must own. vertex_t::store refcounts rather than copies, so durability rests on stored
segments being long-lived. The receive buffer is transient: the ESP-IDF WS link reads a fitting
frame into a once-per-link reusable scratch, falling back to an exact-size
new (std::nothrow) std::byte[frame.len] only for oversized frames
(httpd_ws_link_t::on_data_frame), and either buffer is reused or dies when the receive
call returns, while the rope outlives it — pinned in a last-known-value slot, fanned out
asynchronously, awaited. A borrowed view of that buffer would dangle. Ingress must therefore land
bytes in an owned segment.
Why the pull path pays nothing extra. The TCP serve loop runs frame ingress with no
read-ahead (core/src/transport_tcp.cpp:tcp_transport_t::on_conn): the prefix is read alone, then
the body straight into a segment drawn at its exact length from the injected backend
(core/include/libtracer/frame_ingress.hpp:frame_ingress_t::read), and the next frame’s prefix
rides that same read. The pooled receive target is the owned segment — one kernel copy and zero
user-space copies. The stream servers and the WS client run the same module with a read-ahead
scratch between frames, so a lone small frame costs one read and is copied once, while a body
larger than the scratch still lands in its segment. The only stack scratch on the dial path is
frame ingress’s 256-byte throwaway for a body the source refused, which runs when a frame is
dropped, not when one is delivered.
Where the pull-path shape is not followed, the residual costs are pool-recv questions, not flatten questions:
The ESP-IDF WS link delivers borrowed (
httpd_ws_link_t::deliver), forcing a downstream ownership copy at store. The per-framenew[]itself is gone for fitting frames (they read into the once-per-link scratch); the residual is the shape: landing the payload in a bounded rx pool, adopting it and delivering owning — the TCP/UDP shape — would, by feeding the rope tier an owned segment, let the branch and field decode collapse to refcount bumps once the sink is rope-native.WS reassembly (⑧) used to regrow a copy buffer per fragment, O(n²) in total bytes copied. Since #2483 the httpd link receives each fragment straight into a segment and chains it with the shared assembler (
core/include/libtracer/ws_assembler.hpp:ws_assembler_t::on_piece), the CAN model and what core’s WS links do: no copy on an owning link.
The DEVICE-link constraint never conflicts with pool-recv. Receive targets are always host
memory, so a host pool slot is a legal recv-and-adopt target; only a CPU-side flatten of a DEVICE
link would fault, and flatten refuses that up front (core/src/rope.cpp:rope_t::flatten_core) — as
flatten_err_t::NOT_HOST, a verdict no retry clears, kept distinct from the allocator’s.
Removing even the ownership copy requires LWIP_NETCONN plus a pbuf-wrapping mem_backend
(destroy = pbuf_free, the pbuf is the rope link). That collapses ①, but it is non-portable — no
pbuf on a Linux host — and incompatible with esp_http_server’s WS framing. For a BSD-socket API,
① stays.
Every pool-recv change shares one precondition, and it is built. A segment
self-routes reclaim on whichever subscriber thread drops the last reference, concurrent with a
writer’s alloc, so the receive backend must be thread-safe. synchronized_pool_t<Sync>
(core/include/libtracer/mem_pool.hpp:synchronized_pool_t) is that backend, with the critical section as a
compile-time policy
(ADR-0060, LKV copy store and injected value backend
§2, selected per target as a module-set trait
(ADR-0047, build-time closed module sets
§2): a host keeps synchronized_pool_t<> over its mutex guard, and a single-core priority-preemptive target — where
a lower-priority slot-holder cannot run while a higher-priority task spins — takes the
interrupt-disable tr::esp::critical_pool_t from the ESP-IDF component
(integrations/esp-idf/libtracer/include/libtracer_esp/critical_pool.hpp; it needs FreeRTOS
headers, so it is not in core/). It is opt-in construction: no seam defaults to a pool.
6. Removal candidates, ranked by value¶
Ranked by value on single-link traffic for a single-core, RAM-constrained node, with the saving and the gate.
Rank |
Change |
Removes |
Saving |
Fires on the single-link path? |
Gate |
|---|---|---|---|---|---|
1 |
Streaming branch decode (walk-callback driven, no node array) |
④’s node array |
The stack high-water half LANDED with #2879: the arena draws from the table source, not a 4 KiB stack array. What remains is the node array’s pool draw. |
yes — always paid |
Latency: the walk stack becomes pool- or heap-drawn |
2 |
WS receive into a pooled segment, deliver owning — LANDED for the ESP |
⑧’s per-frame |
One allocation per WS frame per session removed, and the rope tier gets an owned segment |
yes — every WS frame |
Changes the WS delivery contract, which is why it is opt-in and per link rather than a flip; the pool is the INTEGRATOR’s injection, not a library buffer |
3 |
Rope-native branch and field node type |
②③, the multi-link branch/field flatten |
Nothing on single-link, which is a refcount bump; one flatten becomes a refcount bump on fragmented POINT writes |
no — multi-link only |
Ratification-gated sink type (ADR-0041 §2); needs rank 1 to matter |
4 |
Rope-native walk accessors plus a scatter-gather reply head |
⑥, the per-straddling-node |
On straddling route TLVs, fuses flatten and memcpy into one gather |
no — multi-link only |
Converts the shared span-based |
5 |
Rope-chaining WS reassembler — LANDED (#2483: the httpd link shares core’s |
⑧’s O(n²) regrow |
O(n²) → zero copies on an owning link, one on a borrowed one; no 2×n transient heap peak. Fragmentation may worsen (k small segments), and each fragment is charged its segment and chain slot against the cap. |
no — fragmented only |
— |
— |
|
①, the ingress ownership copy |
Collapses even the structural copy |
yes |
Non-portable (no pbuf on a Linux host); incompatible with |
— |
Raw |
⑨, the TX gather |
One full-payload allocation and memcpy per frame per peer |
yes |
Abandons the threadless HTTP-server seam; breaks the |
Structural copies¶
① the ingress ownership copy — a transient receive buffer cannot be borrowed by a rope that outlives it. On the pull path it is the recv: one kernel copy, zero user-space copies. Removable only by the non-portable
LWIP_NETCONNroute.⑤
own_wire— a mutated multi-link value must own a patchable contiguous segment (ADR-0041 §2). This step is the ownership copy, not its removal.⑨ the WS TX gather —
httpd_ws_send_frame_asynctakes one contiguous{payload, len}andhttpd_queue_workis asynchronous, so the rope links are gone before the send runs; the reply must be flattened into one owned buffer.httpd_ws_link_t::queue_sendgathers once, straight into a pre-allocated tx work slot claimed lock-free (nothrow heap only for an oversize payload; an exhausted pool drops and counts, #949), and the directed reply path hands it the reply rope’s iovec with no intermediate flatten temporary. One irreducible gather-copy remains — now allocation-free in steady state. It is the price of threadlessness — riding the existing HTTP-server task, adding no FreeRTOS task — and is removable only by leaving the seam. The rope cursor is irrelevant to it: the sink is a send API, not a decoder.⑫ reply-route synthesis —
tlv_sliced(core/src/fwd_reply.hpp:emit_cursor_t::tlv_sliced) emits rewritten route wires. Bounded at tens of bytes, never payload-scaled.