From 36bffe38500e67ab36ec4d8d7b3d5e1017c70608 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Sat, 14 Nov 2026 00:57:22 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m1/ffi-speed/bytes-write.md Quest-Claim: 2a1011067abac4a7 From fda9b32fa1bbe0a48520dabde85108f4f21d506a Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Sat, 14 Nov 2026 01:50:47 -0800 Subject: [PATCH 2/2] perf(ffi): confirm owned buffers cost a 100 B write nothing Re-measured Swift's and Dart's 100 B write against 7008d1d3, interleaved: neither costs more than before #744. Also fix the Go bench's reader loop, which still passed a Timestamp by value after #742. Co-Authored-By: Claude Opus 5.5 --- bench/ffi/README.md | 8 ++++++++ ffi/moq/bench/export.go | 2 +- quest/m1/ffi-speed/bytes-write.md | 21 --------------------- 3 files changed, 9 insertions(+), 22 deletions(-) delete mode 100644 quest/m1/ffi-speed/bytes-write.md diff --git a/bench/ffi/README.md b/bench/ffi/README.md index 4cb4cce64..56c3dc612 100644 --- a/bench/ffi/README.md +++ b/bench/ffi/README.md @@ -193,6 +193,14 @@ each copies a 100 B frame as often as main does. Kotlin and Go each moved within Bytes Rust returned and a binding passes back cross with no copy, which `ffi/tests` checks by address and by drop count. +Re-measured 2026-11-14 on **nixos** (AMD Ryzen 9 5900XT) at rust2 `79c46e70`, which adds +[#742](https://github.com/kixel-ai/rust2/pull/742)'s by-value `Timestamp`, against +`7008d1d3`, in turn four times at a load of 5 to 8: a 100 B write cost Swift 124 to 127 ns +of CPU against 149 to 176, and Dart 236 to 243 against 239 to 346 (241 to 247 in the three +pairs below load 7). So neither write costs more than it did before #744. A profile of +Swift's shows nothing of `Native.take` or its `Owner` outside the inlined call, and Dart's +100 B write adds two compares and two null checks a call, below what these runs resolve. + CPU time counts every thread of the process: the JVM's JIT and GC threads, Go's GC, and the Swift global executor's workers. So Kotlin's CPU column runs above its wall column, and Swift's woken read spends 14.1 us of CPU for 4.8 us of wall. Throughput from 16 KiB up is diff --git a/ffi/moq/bench/export.go b/ffi/moq/bench/export.go index 3aec7b8d2..016596c57 100644 --- a/ffi/moq/bench/export.go +++ b/ffi/moq/bench/export.go @@ -295,7 +295,7 @@ func round() []result { group := must(track.AppendGroup()) for range frames { <-permits - check(group.WriteFrame(at, frame)) + check(group.WriteFrame(&at, frame)) } <-permits // Keep this group until its reader has consumed every frame. check(group.Finish()) diff --git a/quest/m1/ffi-speed/bytes-write.md b/quest/m1/ffi-speed/bytes-write.md deleted file mode 100644 index 07b25e808..000000000 --- a/quest/m1/ffi-speed/bytes-write.md +++ /dev/null @@ -1,21 +0,0 @@ -# [S] Owned buffers cost a write nothing - -## Goal - -A 100 B write on [the binding benchmark](/bench/ffi/README.md) costs Swift and Dart no more -CPU time than it did before [kixel-ai/rust2#744](https://github.com/kixel-ai/rust2/pull/744) -made Swift's bytes `Bytes` and gave Dart's calls buffers Rust takes, measured against -`7008d1d3` at the same load. - -## Plan - -#744 measured the write four times against `7008d1d3` on a quiet host (load 2 to 3): Swift -179 against 173 ns and Dart 214 against 203, in every pair, while each copies a 100 B frame -as often as before. The generated Swift differs only in `Native.take(Bytes)` against -`Native.view(Data)`, so the cost is per call, not a copy. - -- Profile both writes (`perf record` on `target/bench-export-swift` and the Dart program) - against `7008d1d3`'s, and remove what the new path adds: in Swift, likely what `Bytes` - costs to pass and unwrap; in Dart, the `take` flag's checks, `took()`, and the `_given` - and `_viewed` bookkeeping per call. -- Re-measure the two rows interleaved with `7008d1d3`, and update the benchmark's tables.