osfs: Add zero-copy Bytes to mmap-backed files #243
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 203 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.318
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #243"
general
weight: 0.35
pjbgf
WithMmapmaps read-only files, but the mapping is only reachable throughReadandReadAt, which copy into the caller's buffer and synchronise withCloseon every call. Consumers that parse large files in place, such as go-git's pack/idx/rev scanner, therefore carry their own mmap code that pulls the descriptor out of thebilly.File, and that code cannot use files opened withWithMmapat all, as those expose no descriptor.Add
billy.BytesFile, an optionalFileinterface discovered by type assertion likeLockerandSyncer. ItsBytes() ([]byte, bool)returns the contents without copying, and reports false when they are not available in place, such as once the file is closed. The slice is valid untilCloseand must not be modified. The mmap-backedosfsfile implements it by returning the mapping itself.The chroot and mount wrappers embed
billy.File, which hides every optional method of the wrapped file, andRootOS.Chrootwraps each file it opens. Both now forwardBytes, reporting false when the wrapped file does not implement it, so the interface survives the chroot go-git uses to reach its pack files.This supersedes #226 by @pjbgf, which has the same goal. It differs in that the wrappers forward the method, which #226 leaves hidden behind a chroot;
Bytesreports whether the contents are available, so a wrapper can always forward it; and there is noMmapCapabilitybit orSlicemethod. Whether a file provides its contents in place is decided per open, so only the type assertion on the returned file is reliable, and callers can slice the result ofBytesthemselves.