Skip to content

perf(native): streamline retained staged publication - #948

Closed
steipete wants to merge 5 commits into
mainfrom
perf/native-publication-parity
Closed

steipete wants to merge 5 commits into
mainfrom
perf/native-publication-parity

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Native buffered create and replacement writes were paying for asynchronous Root descriptor ownership and repeatedly walking staging-directory paths after native parent admission. This change keeps descriptor-relative staging and atomic no-replace publication, while opening/closing the retained Root synchronously, validating canonical staging directories through their retained descriptors, and writing callback-free buffers up to 64 KiB through the shared synchronous write loop. Direct-publication buffers, streams, larger buffers, and mutation-assertion writes keep their existing asynchronous path.

Changelog: Performance: Reduce native buffered creation and replacement-write overhead while retaining descriptor-relative publication and exact identity checks.

TypeScript check replaced What subsumes it Why equivalent or stronger
Separate ordinary POSIX parent receipt and pathname checks Exact descriptor capture plus stagedDirectoryMatches The same admitted parent is checked for directory type, exact named/retained device and inode, nonzero retained link count, and canonical descriptor path before staging. Sibling changes may alter the directory link count; policy-specific observations retain their separate stronger checks.
Staging parent lstat + realpath fence for a canonical spelling stagedDirectoryMatches at that fence It checks the no-follow named directory against the receipt's exact device/inode, verifies the retained descriptor's type/link count/identity, and compares its canonical path. Noncanonical spellings and unavailable native observations keep the previous check.
Separate post-match JavaScript fstat for nonprivate stages stagedFileMetadata The native helper compares the same descriptor-relative named entry with a fresh retained-descriptor stat, and returns its exact mode/link count. The owned descriptor cannot change between those synchronous samples. Private stages retain the full-stat path; all hardlink and mode checks remain.
Data-read access on the final Windows verification reopen Optional openPublicationMetadata The same handle-relative, reparse-rejecting child open supplies a metadata handle. All later identity, hardlink, mode, canonical-path and post-operation checks remain. Verification never reads payload bytes, and durability still flushes the original writable handle. Callbacks, private creation and direct publication retain the original reopen.

Opening/closing the Root and writing small buffers change scheduling only; they remove no identity, confinement, symlink, hardlink, policy, permission, durability, or post-publication check. The bounded write loop still handles partial writes and rejects zero progress. No native-capable operation is redirected to TypeScript publication. Existing and older bindings keep the guarded observation fallback.

Validation uses interleaved main/candidate A/B and main A/A controls on dedicated Linux and Windows AWS leases: 27 rotating/reversed blocks, 100 calls per arm. Main is e26eff53; Linux fixtures are on verified ext4, Windows on NTFS with a source-built binding. Earlier /tmp measurements are excluded because that mount is tmpfs. macOS timing remains unmeasured because no requested remote lease provisioned.

Platform / operation / durable Main off / require ns Candidate off / require / auto ns
Linux ext4 / create / false 273,916 / 391,009 276,914 / 269,240 / 270,414
Linux ext4 / write / false 614,926 / 662,557 615,263 / 616,573 / 616,675
Linux ext4 / create / true 3,380,286 / 5,195,410 3,382,905 / 5,067,438 / 5,066,341
Linux ext4 / write / true 5,442,469 / 5,380,447 5,450,631 / 5,224,306 / 5,231,331
Windows NTFS / create / false 1,390,771 / 1,993,604 1,425,274 / 1,400,973 / 1,373,612
Windows NTFS / write / false 2,597,527 / 2,491,310 2,683,705 / 2,407,912 / 2,384,487
Windows NTFS / create / true 4,736,261 / 6,755,921 4,790,780 / 6,254,988 / 6,175,664
Windows NTFS / write / true 7,841,117 / 7,093,686 7,860,883 / 7,021,753 / 7,005,711

Non-durable publication is at parity or better within the observed A/A control variation, and durable replacement write is faster with native. Durable creation remains a measured exception: native preserves complete staged publication and content-before-rename durability ordering; default fallback creation writes its final name directly. No required flush or publication guarantee is removed. The remaining cost is recorded for follow-up and is not claimed as parity.

Native Linux create/write are pinned at 62/72 filesystem calls and 88/117 promises. Fallback counts are 40/50 calls and 102/143 promises after the current-main rebase. All eight native budget operations pass in normal and forced-openat modes, including the retained mkdir/ensureRoot/move worker pins. Windows tests pin the metadata reopen and verify descriptor ownership, mode access, and refusal of data reads.

A deterministic sibling-churn regression failed before correcting ordinary parent admission (APFS changes directory link counts for sibling files). Ordinary publication uses its identity/canonical contract; stricter native-directory and policy admission retain their existing checks. Fault-injection tests cover both legacy and new native entry points.

The full Linux check, workspace Rust tests, strict Linux clippy, Windows source build and focused tests, and P0–P2 independent review passed after rebasing. Exact-head CI is green for 14abdee0487e8af46f08a622bc038c7925d2bbdf. The earlier supplemental Windows Rust 1.99 clippy run exposed pre-existing Windows-only lint warnings; repository lint settings were not changed.

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR reduces native staged-publication overhead through synchronous descriptor ownership, bounded buffer writes, and combined identity observations.

Example: Native Root.create("state.txt", "data", { durable: false }) without a mutation callback.

  • Before: Root descriptor ownership and the four-byte staged write use asynchronous filesystem dispatch.
  • After: Descriptor ownership and the staged write use synchronous dispatch while retaining publication and identity checks.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Reported runtime comparisons and focused safety coverage support useful work, but the verified allocation regression and changelog omission still block landing.
Proof confidence 🦐 gold shrimp (3/6) The supplied maintainer-authored status exempts ordinary contributor proof; the body reports real ext4/NTFS create/write comparisons, while inspected tests exercise the changed owners and no new authorization boundary was identified.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Small native file creations and replacement writes incur unnecessary descriptor, observation, and scheduling overhead.
Reason: The supplied maintainer-authored direction and reported ext4/NTFS comparisons support the optimization without changing public options or defaults.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this PR open: the optimization remains distinct from main, its designated landing batch is open, and both previously reported repairs remain unresolved.

Priority: P2
Reviewed head: 14abdee0487e8af46f08a622bc038c7925d2bbdf

Before merge

  • Reuse encoded bytes when the small-buffer path is ineligible (P2) - For a callback-free native staged write of "x".repeat(1048576), Buffer.from encodes and allocates 1 MiB before the size check rejects synchronous dispatch. The asynchronous branch at line 65 then encodes the same string again, whereas main encodes it once. Carry the encoded bytes into asynchronous dispatch to avoid the extra allocation and encoding work. This previously reported finding remains unresolved at the same reviewed head.
  • Record the measured performance improvement under Unreleased (P3) - The measured native creation and replacement-write improvement is release-relevant, but CHANGELOG.md has no corresponding entry. Root AGENTS.md requires measured performance improvements under Unreleased. Add a concise Performance entry; proposed wording in the PR body does not update the package changelog. This previously reported finding remains unresolved.

Findings

  • [P2] Reuse encoded bytes when the small-buffer path is ineligible — src/pinned-write-input.ts:48-49
  • [P3] Record the measured performance improvement under Unreleased — CHANGELOG.md:11

Tests

  • Missing end-to-end proof: Supplied validation does not demonstrate base-fail/head-pass execution of the added small-buffer regressions.
Agent review details

How this fits together

Root and secret-file writers pass admitted directories and payloads into retained-directory staging, which writes, publishes, verifies, and cleans up owned files.

flowchart TD
A[Root or secret writer] --> B[Root and parent admission]
B --> C[Retained directory]
C --> D[Owned staged file]
D --> E[Buffered or streamed write]
E --> F[Atomic publication]
F --> G[Identity and permission checks]
Loading

Technical review

Best possible solution:

Retain the optimization, reuse encoded bytes on asynchronous fallthrough, and add the measured improvement under Unreleased before landing the shared batch.

Do we have a high-confidence way to reproduce the issue?

Source establishes duplicate encoding for a callback-free native staged write of "x".repeat(1048576); no target code was executed.

Is this the best way to solve the issue?

The optimization fits the existing staging owners and preserves the inspected safety contracts, but asynchronous fallthrough should reuse the first encoding.

Full review comments:

  • [P2] Reuse encoded bytes when the small-buffer path is ineligible — src/pinned-write-input.ts:48-49
    For a callback-free native staged write of "x".repeat(1048576), Buffer.from encodes and allocates 1 MiB before the size check rejects synchronous dispatch. The asynchronous branch at line 65 then encodes the same string again, whereas main encodes it once. Carry the encoded bytes into asynchronous dispatch to avoid the extra allocation and encoding work. This previously reported finding remains unresolved at the same reviewed head.
    Confidence: 1
  • [P3] Record the measured performance improvement under Unreleased — CHANGELOG.md:11
    The measured native creation and replacement-write improvement is release-relevant, but CHANGELOG.md has no corresponding entry. Root AGENTS.md requires measured performance improvements under Unreleased. Add a concise Performance entry; proposed wording in the PR body does not update the package changelog. This previously reported finding remains unresolved.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e26eff537588.

Provenance checked

  • Root descriptor ownership changes intended behavior with a stated reason (5fe53dd: Retain and verify Root authority for confined native operations; this PR explains replacing asynchronous ownership with synchronous ownership to reduce overhead.)
  • Retained-directory staging and cleanup keeps the original intent (d733275: Keep cleanup attached to the admitted directory and staged contents private until publication identity checks pass.)
  • Staged-file metadata verification keeps the original intent (8dbb453: Consolidate resource ownership while preserving exact identity checks, permission fences, and cleanup precedence.)
  • Shared write loop and mutation authority keeps the original intent (7274d7e: Check current caller authority immediately before mutation dispatch, including partial-write retries; callback-bearing writes retain that path.)
  • Windows publication verification reopen changes intended behavior with a stated reason (d733275: Fence the published file before applying final permissions; this PR explains using metadata access for eligible verification without reading payload bytes.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d733275 adds src/native-staged-file.ts:134 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d73327569edf; files: src/native-staged-file.ts)

Root-cause cluster

Relationship: superseded
Canonical: #952
Summary: The designated landing batch contains the identical tree and explicitly retains this original PR until landing.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: Useful performance work introduces an extra payload-sized allocation and encoding for large staged strings.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (7 earlier review cycles)
  • reviewed 2026-10-11T10:07:07.569Z sha 19ab088 :: needs changes before merge. :: [P2] Reuse the encoded bytes when the small-buffer path is ineligible
  • reviewed 2026-10-11T10:17:24.135Z sha 19ab088 :: needs changes before merge. :: [P2] Reuse the encoded bytes when the small-buffer path is ineligible
  • reviewed 2026-10-11T11:16:01.397Z sha 0131dce :: needs changes before merge. :: [P2] Reuse encoded bytes when the small-buffer path is ineligible | [P2] Inject the final-mode swap through metadata reopens too | [P3] Record the performance improvement under Unreleased
  • reviewed 2026-10-11T11:30:06.614Z sha 0a9f0a3 :: needs changes before merge. :: [P2] Reuse encoded bytes when the small-buffer path is ineligible | [P3] Record the performance improvement under Unreleased
  • reviewed 2026-10-11T12:19:39.313Z sha 49d6361 :: needs changes before merge. :: [P2] Reuse encoded bytes when the small-buffer path is ineligible | [P3] Record the performance improvement under Unreleased
  • reviewed 2026-10-11T12:39:15.647Z sha 49d6361 :: needs changes before merge. :: [P2] Reuse encoded bytes when the small-buffer path is ineligible | [P3] Record the performance improvement under Unreleased
  • reviewed 2026-10-11T13:14:54.170Z sha 14abdee :: needs changes before merge. :: [P2] Reuse encoded bytes when the small-buffer path is ineligible | [P3] Record the performance improvement under Unreleased

Reviewed October 11, 2026, 9:49 AM ET / 13:49 UTC (Revision 8).

@steipete
steipete force-pushed the perf/native-publication-parity branch from 19ab088 to 0131dce Compare October 11, 2026 10:57
@steipete
steipete marked this pull request as ready for review October 11, 2026 12:36
@steipete
steipete requested a review from a team as a code owner October 11, 2026 12:36
@steipete steipete added campaign-ready Campaign PR: reviewed, CI green, ready for the serial lander campaign-blocked Campaign PR: lander could not land (conflict or persistent CI failure) and removed campaign-ready Campaign PR: reviewed, CI green, ready for the serial lander labels Oct 11, 2026
@steipete
steipete force-pushed the perf/native-publication-parity branch from 49d6361 to 14abdee Compare October 11, 2026 13:01
@steipete steipete added campaign-ready Campaign PR: reviewed, CI green, ready for the serial lander and removed campaign-blocked Campaign PR: lander could not land (conflict or persistent CI failure) labels Oct 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 11, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Landed on main as 70aa9f5 through campaign batch #952 (rebase merge keeps this PR as its own commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

campaign-ready Campaign PR: reviewed, CI green, ready for the serial lander P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant