Skip to content

refactor(fspy): simplify shm_io to a plain frame arena - #578

Open
wan9chi wants to merge 1 commit into
fspy-close-gatefrom
fspy-plain-frame-arena
Open

refactor(fspy): simplify shm_io to a plain frame arena#578
wan9chi wants to merge 1 commit into
fspy-close-gatefrom
fspy-plain-frame-arena

Conversation

@wan9chi

@wan9chi wan9chi commented Jul 28, 2026

Copy link
Copy Markdown
Member

Motivation

The gated API reads shared memory only when the gate is closed and nothing was in flight, which proves every claimed frame was written in full; the gate guard is released after the frame drops. The three-state frame header (0 / +size / -size), the atomic header stores and the release fences in shm_io existed so a reader could tolerate crashed or in-flight writers. Those states are unreachable through the gated API.

This PR deletes them. The arena keeps one atomic, its end-offset word. A frame becomes | size: u32 | content | padding |, written once at claim time with a plain store: the claim made the range exclusive, and the gate release publishes the content. Crash exclusion lives in the gate, where a leaked count means the run is not cached. The arena stops being a public surface and becomes an internal of the gated module. Mapping::as_slice goes away with its last caller, which leaves fspy_shm without unsafe API.

write_encoded enters the gate before it sizes the value, so a post-close call reports Claim(Closed) for any value, including one that encodes to zero bytes.

No public API change: GatedShmWriter, GatedShmReceiver, GatedShmReader, FrameMut, ClaimError and StillWriting keep their signatures. The channel layer, the fspy crate and both preload clients are untouched.

🤖 Generated with Claude Code

wan9chi commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  +0.83%  [ -6.13% ..  +8.72%]  overhead  +272.62%
dynamic/access             change  -3.38%  [ -3.95% ..  -2.60%]  overhead   +60.86%
static/launch              change  -0.53%  [ -8.55% .. +10.90%]  overhead  +646.86%
static/access              change  +0.80%  [ -0.24% ..  +1.95%]  overhead  +851.14%

macos

dynamic/launch             change  -0.53%  [ -2.87% ..  +1.61%]  overhead  +216.26%
dynamic/access             change  -2.89%  [ -5.57% ..  +0.00%]  overhead   +23.64%

windows

dynamic/launch             change  +0.13%  [ -3.11% ..  +4.27%]  overhead   +27.23%
dynamic/access             change  -0.35%  [ -1.26% ..  +0.53%]  overhead    +9.11%

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b03e50b979

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fspy_shared/src/ipc/channel/gated.rs
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 9485184 to a815712 Compare July 28, 2026 11:18
@wan9chi
wan9chi force-pushed the fspy-close-gate branch 2 times, most recently from 2788743 to e910409 Compare July 28, 2026 11:20
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from 98eff10 to 4deba7a Compare July 29, 2026 01:22
@wan9chi
wan9chi force-pushed the fspy-close-gate branch 2 times, most recently from 1d7e957 to 0f5db93 Compare July 29, 2026 02:14
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 4deba7a to d5fee65 Compare July 29, 2026 02:14
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from 43075cc to b8e397b Compare July 30, 2026 02:14
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from b8e397b to b6e4c6e Compare July 30, 2026 03:24
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from b6e4c6e to fb46de4 Compare July 30, 2026 03:43
@wan9chi
wan9chi force-pushed the fspy-close-gate branch 2 times, most recently from 4fb1a00 to 38d6107 Compare July 30, 2026 03:48
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch 2 times, most recently from d341ace to b5602be Compare July 30, 2026 03:51
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from b5602be to 2ecce74 Compare July 30, 2026 04:11
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 2ecce74 to 7c7e5c2 Compare July 30, 2026 04:36
@wan9chi
wan9chi force-pushed the fspy-close-gate branch 2 times, most recently from 5d642d1 to cdff4d6 Compare July 30, 2026 06:12
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 7c7e5c2 to 37a65cf Compare July 30, 2026 06:12
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 37a65cf to c43a320 Compare July 30, 2026 07:12
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from c43a320 to 394709d Compare July 30, 2026 07:35
The gated API reads shared memory only when the gate is closed and nothing
was in flight, which proves every claimed frame was fully written and
published. The three-state frame header (`0` / `+size` / `-size`), the
atomic header stores and the release fences existed so a reader could
tolerate crashed or in-flight writers — states that are unreachable through
the gate.

Delete them. A frame is now `| size: u32 | content | padding |`, written
once at claim time with a plain store, and the arena keeps exactly one
atomic: its end offset. Crash exclusion lives entirely in the gate, where a
leaked count fails closed — the run is not cached — instead of being parsed
around. The arena also stops being a surface of its own and becomes an
internal of the gated module.

No public API change: `GatedShmWriter`, `GatedShmReceiver`,
`GatedShmReader`, `FrameMut`, `ClaimError` and `StillWriting` keep their
signatures, so the channel layer, the fspy crate and both preload clients
are untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wan9chi
wan9chi force-pushed the fspy-plain-frame-arena branch from 394709d to 37f066a Compare July 30, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant