Skip to content

feat(fspy-ipc-str): convert IpcStr and platform C strings directly - #669

Merged
wan9chi merged 4 commits into
agent/fspy-shm-nostd-apifrom
agent/fspy-ipc-str-oscstr
Aug 14, 2026
Merged

feat(fspy-ipc-str): convert IpcStr and platform C strings directly#669
wan9chi merged 4 commits into
agent/fspy-shm-nostd-apifrom
agent/fspy-ipc-str-oscstr

Conversation

@wan9chi

@wan9chi wan9chi commented Aug 14, 2026

Copy link
Copy Markdown
Member

Motivation

The shm id still crossed the process boundary through OsStr: on Windows, IpcStr's UTF-16 bytes were decoded to WTF-8 (OsString) and re-encoded back to UTF-16 — two global-allocator allocations while the preload attaches under the loader lock. The preload is going std-free bottom-to-top, and the allocator is the bottom, so this lands the cross-platform arena together with its first consumer.

Built in commit order:

  • fspy_nostd: VirtualAlloc/VirtualFree wrappers — kernel calls that never touch the CRT heap lock, usable under the loader lock.
  • fspy_nostd_alloc: VirtualAllocator, the stateless Windows twin of MmapAllocator; the chunk pool and arena() now compile on every platform over a platform-selected page allocator.
  • fspy_ipc_str: from_os_c_str borrows an OsCStr's units zero-copy, and to_os_c_string_in decodes into a caller-chosen allocator, reading Windows code units bytewise so IpcStr's unaligned representation never matters. Neither direction touches OsStr.
  • fspy_shared: channel() serializes the id straight from the keeper's C string, and sender() decodes it with the arena — no OsStr round trip and no global-allocator use on the attach path.

Stack created with GitHub Stacks CLIGive Feedback 💬

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  +1.78%  [ -4.05% ..  +7.79%]  overhead   +52.89%
dynamic/access             change  -0.41%  [ -7.52% .. +21.74%]  overhead    +5.90%
dynamic/access-relative    change  -0.74%  [-15.43% ..  +2.43%]  overhead   +50.67%
static/launch              change  +0.77%  [ -5.50% ..  +7.67%]  overhead  +154.05%
static/access              change  +0.42%  [ -3.21% ..  +4.99%]  overhead  +739.36%
static/access-relative     change  -0.01%  [ -1.88% ..  +1.27%]  overhead +1179.16%

macos

dynamic/launch             change  -0.12%  [ -4.66% ..  +3.90%]  overhead  +219.31%
dynamic/access             change  +0.35%  [ -4.70% ..  +6.55%]  overhead    +6.01%
dynamic/access-relative    change  +0.53%  [ -1.88% ..  +3.96%]  overhead  +259.77%

windows

dynamic/launch             change  -0.47%  [ -4.29% ..  +2.26%]  overhead   +27.38%
dynamic/access             change  +0.18%  [ -1.28% ..  +1.44%]  overhead    +1.51%
dynamic/access-relative    change  +0.55%  [ -1.08% ..  +2.16%]  overhead    +1.82%

wan9chi and others added 2 commits August 14, 2026 09:55
VirtualAlloc at a system-chosen address and the matching MEM_RELEASE
VirtualFree, both kernel calls that never touch the CRT heap lock, so
they are usable under the loader lock. This is the bottom layer for a
cross-platform fspy_nostd_alloc page allocator.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
VirtualAllocator is the Windows twin of MmapAllocator: stateless, one
fresh committed region per allocation, released as a whole — kernel
calls only, so it works under the loader lock. The chunk pool and arena
build on a platform-selected PageAllocator and now compile everywhere.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wan9chi
wan9chi force-pushed the agent/fspy-ipc-str-oscstr branch from 5f21a43 to b929875 Compare August 14, 2026 01:56
wan9chi and others added 2 commits August 14, 2026 10:29
from_os_c_str borrows the units of an OsCStr zero-copy, and
to_os_c_string_in decodes into an OsCString in a caller-chosen
allocator, reading Windows code units bytewise so the unaligned IpcStr
representation never matters. Neither direction touches OsStr, so both
work without std. to_boxed rounds out ownership for callers that store
the result.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
channel() serializes the shm id straight from the keeper's C string via
IpcStr::from_os_c_str, and sender() decodes it with to_os_c_string_in
backed by the fspy_nostd_alloc arena — removing the UTF-16 to WTF-8 to
UTF-16 round trip and the global-allocator use on the preload attach
path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wan9chi
wan9chi force-pushed the agent/fspy-ipc-str-oscstr branch from b929875 to 2648b62 Compare August 14, 2026 02:29
@wan9chi wan9chi changed the title agent/fspy ipc str oscstr feat(fspy-ipc-str): convert IpcStr and platform C strings directly Aug 14, 2026
@wan9chi
wan9chi marked this pull request as ready for review August 14, 2026 03:14
@wan9chi
wan9chi merged commit 0fd7673 into main Aug 14, 2026
19 checks passed
@wan9chi
wan9chi deleted the agent/fspy-ipc-str-oscstr branch August 14, 2026 03:14
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