The expensive part of receiving a live stream was not necessarily receiving it. The first profile put memmove at 34.4% of samples. Its largest callers were turning a compact timeline raster into a full-height image and repacking that image for the GPU.
A real client, a repeatable stream
The load comes from perfr's benchmark producer: 16 synthetic threads, nesting depths from 8 to 16, configured for 1,000,000 events per second. A separate service sends its normal packed WebSocket stream. The target is the native client's shared viewer, running in a real eframe/wgpu window at 1280 × 800 logical points and 2× display scaling. It follows the live tail with its default two-second view. Both the service and the profiling service run separately from the measured client. The native client and browser client share the rendering code changed here.
A small native example wraps the existing application. It records update duration and frame start intervals, polls the application's pending-message queue once a second, and exits after 35 seconds. A Python runner records process CPU time, resident memory, and producer counters. It does not drive a synthetic render loop. The Self pane remains closed.
Follow the copies
The diagnostic capture combines 1 kHz CPU sampling with three narrowly selected function hooks. Out of 13,352 samples, 4,597 landed in memmove. Call stacks assign 16.1% of all samples to pack_rgba_aligned → memmove, and another 11.3% to to_rgba8_placed → memmove. The column rasterizer itself accounts for 21.0% self and 30.0% inclusive. Ingestion is 12.6% inclusive; packed event decoding is 2.6% inclusive. Inclusive percentages overlap and should not be added.
The hooks explain the copies in units of a frame: across 1,571 calls, row repacking averages 1.563 ms and building the placed image averages 1.211 ms. Those are elapsed hook durations from an instrumented run, not our end-to-end benchmark. They identify where to investigate.
Open the before story · Download the capture bundle, stream, or story JSON.
First, remove a rule that does not apply
The upload helper allocated a second image, rounded each row's stride up to 256 bytes, and copied every row. That alignment is required by encoder buffer-to-texture copies. It is explicitly not required by Queue::write_texture, the API this renderer uses. Passing the original tightly packed bytes removes the allocation and copy. The renderer's wgpu dependency is pinned to 25; the exemption is documented beside COPY_BYTES_PER_ROW_ALIGNMENT in that version's source.
This substantially reduces GPU preparation time, but does not by itself guarantee a comparable improvement in total CPU use. The raster image is still large, still allocated every changing frame, and still copied internally by the upload API. The intermediate build is measured below rather than folded into the final result.
The experiment we did not keep
At the pixel-column level of detail, the rasterizer has already reduced each lane to one horizontal row of colors. The previous path converted that row to RGBA, copied it down the lane's height, and left blank image rows for the gaps between tracks. A lane displayed 20 pixels tall did not contain 20 different rows of information.
The experimental path uploads those rows as a compact texture and supplies a 16-byte placement record per visible span. The shared blit shader stretches each row vertically, sampling its center with nearest filtering. Existing overlays, focus dimming, search colors, scrolling, and drag layers keep using the same paths. Service-rendered images use one full-image placement record.
There is a correctness trap here. Layouts can overlap during transitions, and a later lane's transparent pixels previously erased the pixels below them. Alpha-blending two overlapping quads would leave the earlier lane visible. Before emitting quads, the experiment resolves which lane owns each destination row, then merges consecutive rows with the same owner. The resulting spans do not overlap. Tests reconstructed the old full image from these spans and compared every byte across odd widths, gaps, reversed and missing layouts, fractional scales, and transparent overlaps.
This worked visually and passed the reconstruction tests. It reduced the compact conversion hook to 0.215 ms and pushed memory copies down to 3.5% of samples. But it lost to the padding-only build in repeated whole-client CPU measurements and made UI update timings worse. Why its update timings worsened remains unresolved; lower allocation volume alone is not a sufficient explanation. We reverted it. Its capture, story, and experimental patch against the baseline (ZIP) remain available as evidence, not as shipped changes.
Measure the whole client
The retained change reduces mean whole-client CPU from 0.459 to 0.385 CPU cores: 16% less CPU across three runs of each build. Mean timeline GPU preparation falls from 1.85 to 0.37 ms, a 80% reduction. Update latency does not improve; its mean per-run p95 is worse. Frame cadence remains about 60 Hz. This is a CPU-efficiency improvement, not a responsiveness claim.
| Build | CPU cores, mean (range) | GPU prepare, ms | Update p50 / p95, ms | Frame period p95, ms |
|---|---|---|---|---|
| Baseline (3 runs) | 0.459 (0.381–0.508) | 1.851 | 4.22 / 7.30 | 20.06 |
| No padding — retained (3 runs) | 0.385 (0.357–0.407) | 0.372 | 4.40 / 8.21 | 19.94 |
| Compact rows — rejected (2 runs) | 0.449 (0.436–0.463) | 0.044 | 6.18 / 10.12 | 22.37 |
All timed builds use the same release settings and debug information. Hardware: Intel Core i9-13900KF, NVIDIA RTX 4090, driver 595.91.07, Linux 7.0.0-34-generic. Trials alternate builds, with the client restricted to performance CPUs 4 and 6. The powersave governor and balance_performance preference remain unchanged; clocks are not locked. Variation remains visible even with affinity. Each trial lasts 35 seconds; the table excludes the first 15 seconds of frame readings and 16 seconds of process readings. Table quantiles are averaged across runs, not pooled percentiles. Two earlier unrestricted-affinity trials per build are included in the raw archive; those showed a smaller mean CPU reduction (about 6%) for padding removal. Three controlled runs are evidence for this workload, not a universal percentage.
The producer reports approximately one million events per second throughout the measurement windows. Every one-second snapshot has zero bytes in the viewer’s pending-message queue, and all timed clients exit successfully without app errors. That does not prove zero network backlog or end-to-end latency. Around 33–34 million events are retained at the final snapshot; mean RSS is roughly 1.37 GB for both baseline and retained fix, so there is no demonstrated resident-memory saving. The selected build passes 480 relevant native unit tests (8 ignored), the viewer dependency-boundary check, and the threaded WebAssembly pack build. The native window renders at a non-256-byte-aligned timeline row width; the three stories render in browser WebGL and the article fits a 390-pixel viewport. Headless WebGPU initialized but drew a blank page with both baseline and modified packs, so browser WebGPU visual correctness remains unverified; see the validation record.
What becomes the bottleneck?
The retained-build capture contains 10,680 samples. Memory copies now account for 12.8%, while the column rasterizer leads at 24.8% self and 36.8% inclusive. Ingestion is 18.7% inclusive. The old padding helper is absent; the existing placed-image conversion remains. Its hook records 1,333 calls averaging 0.711 ms. These diagnostic captures have different durations and scheduling conditions: the baseline was unpinned, while the retained build used CPUs 4 and 6. Their percentages locate costs; the separate unprofiled runs establish the CPU comparison.
Open the after story · Download the capture bundle, stream, or story JSON.
The remaining raster work chooses a representative event for each visible column, finds the longest overlap, and computes its color. That is the next measured candidate. Ingestion still decodes the packed stream and inserts events into per-lane storage. Neither needs a rewrite to remove the costs found here. Event retention and allocation deserve longer-duration tests: these short runs accumulate events and are not a memory steady-state benchmark.
The code is shared by the native and WebAssembly targets. The measurements here are native measurements; they do not establish a browser speedup, a maximum sustainable event rate, or GPU execution time. No scheduler-based utilization claims are made. The retained improvement is passing the existing image directly to the GPU upload API. It removes a full-frame allocation and copy without changing the rasterizer or shader.
Reproduce and inspect
The implementation PR contains the upload fix and harness in tools/performance/, crates/perfr-client/examples/live_bench.rs, crates/perfr-viewer/src/timeline.rs. The harness README documents building both revisions, starting an isolated service, and repeating the trials. The runner clears that service's capture before every trial.
Per-run summary · Raw frame and process readings · Build and machine manifest · Before hotspots · After hotspots · Before stacks · After stacks.