memory
Skill915 starsChanged 22 days agoMITView on GitHub
Swift 6.2 InlineArray and Span types for zero-overhead memory access, fixed-size collections, and safe pointer alternatives. Use when optimizing performance-critical code paths.
123 other projects use a version of this.
Adopted by
Most recently taken up by
- yezzzp/agent-relay-protocoltheir own version, first seen Nov 29, 2026
- biliboss/skillstheir own version, first seen Nov 29, 2026
- BlinkVoid/GearCoretheir own version, first seen Nov 29, 2026
- matthewwong525/WongStacktheir own version, first seen Nov 29, 2026
- matthewdonsemail-lab/logtheir own version, first seen Nov 29, 2026
- gurinderu/crafttheir own version, first seen Nov 29, 2026
Used with
Projects with it also use ecosystem-reference, fractal-delegation and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
naman10parikhSkillecosystem-reference
Quick-access directory of Claude Code ecosystem repos, skills, plugins, MCPs, and patterns. Use when improving the harness.
Also in 5 projects that use this
naman10parikhSkillfractal-delegation
Also in 5 projects that use this
roronoazoroshao369Skillmemory-compression
Also in 5 projects that use this
Maliot100XSkillsend-user-message
Send a proactive message to a paired user via their channel (Discord, Telegram, or WhatsApp). Use when the agent needs to notify, alert, or send an unsolicited message to a user — especially during heartbeat invocations, scheduled tasks, or when the agent wants to reach out without a prior user message in the current conversation. Triggers: 'send message to user', 'notify user', 'alert user', 'message the user on discord/telegram/whatsapp', or any need to proactively communicate with a paired sender.
Also in 4 projects that use this
jh941213Skilldocs-ci
문서 CI(링크·OpenAPI lint·breaking 게이트·mermaid 검증)나 문서 드리프트 감지(docs.yaml 신선도 검사)를 설치하거나 돌릴 때 사용. 문서 내용 작성은 docs-architecture·docs-interfaces·docs-manuals.
Also in 3 projects that use this
jh941213Skilldocs-interfaces
API·이벤트 인터페이스 문서(OpenAPI·swagger·AsyncAPI 명세, 엔드포인트 레퍼런스, API 구성도·시퀀스, API CHANGELOG)를 만들거나 코드와 맞출 때 사용. 시스템 구성도는 docs-architecture, API 설계 원칙은 api-design-principles.
Also in 3 projects that use this
- +5 more from naman10parikh
- +1 more from jh941213
Other versions123 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 123
- google-gemini/gemini-cli★ 109ksame name
- jlia0/tinyclaw★ 3.6ksame name
- TinyAGI/tinyagi★ 3.6ksame name
- TinyAGI/tinyclaw★ 3.6ksame name
- Chachamaru127/claude-code-harness★ 3.2ksame name
- codeaholicguy/ai-devkit★ 1.7ksame name
- Muuuun/luxas★ 1.2ksame name
- shobcoder/shob★ 575same name
- boshu2/agentops★ 464same name
- makushingu/harness-maxxing★ 302same name
113 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository184 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- app-intentsSkill
- foundation-modelsSkill
- apple-intelligenceSkill
- visual-intelligenceSkill
- ad-attributionSkill
- app-description-writerSkill
- apple-search-adsSkill
- iap-finalizerSkill
- keyword-optimizerSkill
- marketing-strategySkill
- originality-checkSkill
- ratings-mechanicsSkill
- rejection-handlerSkill
- review-response-writerSkill
- screenshot-plannerSkill
- app-storeSkill
- web-presenceSkill
- core-mlSkill
- animation-patternsSkill
- design-systemSkill
- game-feelSkill
- liquid-glassSkill
- sf-symbolsSkill
- designSkill
- typographySkill
- ui-prototypingSkill
- ux-writingSkill
- attributed-stringSkill
- foundationSkill
- accessibility-generatorSkill
- account-deletionSkill
- analytics-setupSkill
- announcement-bannerSkill
- app-clipSkill
- app-extensionsSkill
- app-icon-generatorSkill
- app-store-assetsSkill
- auth-flowSkill
- background-processingSkill
- ci-cd-setupSkill
- cloudkit-syncSkill
- consent-flowSkill
- custom-product-pagesSkill
- data-exportSkill
- debug-menuSkill
- deep-linkingSkill
- error-monitoringSkill
- feature-flagsSkill
- featuring-nominationSkill
- feedback-formSkill
- force-updateSkill
- http-cacheSkill
- image-loadingSkill
- in-app-eventsSkill
- lapsed-userSkill
- live-activity-generatorSkill
- localization-setupSkill
- logging-setupSkill
- milestone-celebrationSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.
0
Common
Most of the 105 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 16
Use this skill when the user:
“Common” is measured: kept by at least 6 in 10 of the 105 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
InlineArray and Span
Guidance for Swift 6.2's low-level memory types: InlineArray for fixed-size inline storage without heap allocation, and Span for safe, zero-cost access to contiguous memory. These replace common uses of UnsafeBufferPointer and hand-tuned tuple storage with compiler-checked alternatives.
When This Skill Activates
Use this skill when the user:
- Asks about InlineArray, fixed-size arrays, or stack-allocated collections
- Mentions Span, MutableSpan, RawSpan, or UTF8Span
- Wants to eliminate heap allocations in hot paths
- Is replacing UnsafeBufferPointer or UnsafePointer with safe alternatives
- Asks about value generics or
let count: Intgeneric parameters - Needs zero-copy access to collection storage
- Mentions inline storage, contiguous memory, or memory layout
- Is doing binary parsing, signal processing, or embedded Swift work
- Wants to avoid copy-on-write overhead for small fixed collections
- Asks about non-escapable types or lifetime dependencies in Swift
Decision Tree
What memory optimization do you need?
│
├─ A fixed-size collection that never grows/shrinks
│ │
│ ├─ Size known at compile time, stored on stack
│ │ └─ InlineArray<N, Element>
│ │ ├─ No heap allocation
│ │ ├─ No reference counting
│ │ └─ No copy-on-write (eager copies)
│ │
│ └─ Size may vary at runtime
│ └─ Array<Element> (standard library)
│
├─ Safe read access to contiguous memory
│ │
│ ├─ Read-only access to typed elements
│ │ └─ Span<Element>
│ │
│ ├─ Mutable access to typed elements
│ │ └─ MutableSpan<Element>
│ │
│ ├─ Read-only access to raw bytes
│ │ └─ RawSpan
│ │
│ ├─ Mutable access to raw bytes
│ │ └─ MutableRawSpan
│ │
│ ├─ Unicode text processing
│ │ └─ UTF8Span
│ │
│ └─ Initializing a new collection's storage
│ └─ OutputSpan
│
├─ Unsafe pointer access (legacy or interop)
│ └─ UnsafeBufferPointer / UnsafeMutableBufferPointer
│ └─ Prefer Span instead for new code
│
└─ Standard dynamic collection
└─ Array<Element>
├─ Heap-allocated, copy-on-write
└─ Grows/shrinks dynamicallyAPI Availability
| API | Minimum Version | Notes |
InlineArray<let count: Int, Element> | Swift 6.2 | Uses value generics; @frozen struct |
Span<Element> | Swift 6.2 | Non-escapable, lifetime-dependent |
MutableSpan<Element> | Swift 6.2 | Mutable variant of Span |
RawSpan | Swift 6.2 | Untyped byte-level access |
MutableRawSpan | Swift 6.2 | Mutable untyped byte access |
UTF8Span | Swift 6.2 | Unicode-aware text processing |
OutputSpan | Swift 6.2 | For initializing collection storage |
.span property on Array / ArraySlice / InlineArray | Swift 6.2 | Returns Span<Element> |
.bytes property on Data | Swift 6.2 | Returns RawSpan (byte-level access) |
[N of T] sugar, InlineArray(repeating:), closure init | Swift 6.4 | [256 of Int] as a type; InlineArray { i in … } (WWDC26 262) |
UniqueArray / UniqueBox / Ref / MutableRef | Swift 6.4 | Noncopyable containers + single-value spans — see swift-performance.md |
Top 5 Mistakes
| # | Mistake | Fix |
| 1 | Trying to append/remove elements on InlineArray | InlineArray is fixed-size; use Array if you need dynamic sizing |
| 2 | Returning a Span from a function | Span is non-escapable and cannot outlive its source; restructure to process data within the same scope |
| 3 | Capturing a Span in a closure | Span cannot be captured; pass the span as a parameter or use Array for escaped contexts |
| 4 | Using InlineArray for large or frequently copied collections | InlineArray copies eagerly (no COW); use Array for large data that is shared or copied often |
| 5 | Accessing a Span after mutating the source container | Mutation invalidates the span; re-acquire the span after any modification |
InlineArray
Declaration
@frozen struct InlineArray<let count: Int, Element> where Element: ~CopyableInitialization
// Explicit count
let a: InlineArray<4, Int> = [1, 2, 4, 8]
// Count inferred from literal
let b: InlineArray<_, Int> = [1, 2, 4, 8] // count = 4
// Element type inferred from literal
let c: InlineArray<4, _> = [1, 2, 4, 8] // Element = Int
// Both inferred
let d: InlineArray = [1, 2, 4, 8] // InlineArray<4, Int>Memory Layout
Elements are stored contiguously with no overhead. Size equals count * MemoryLayout<Element>.stride:
MemoryLayout<InlineArray<0, UInt16>>.size // 0
MemoryLayout<InlineArray<0, UInt16>>.stride // 1
MemoryLayout<InlineArray<3, UInt16>>.size // 6 (2 bytes x 3)
MemoryLayout<InlineArray<3, UInt16>>.stride // 6
MemoryLayout<InlineArray<3, UInt16>>.alignment // 2 (same as UInt16)Basic Usage
var array: InlineArray<3, Int> = [1, 2, 3]
// Subscript access
array[0] = 4
// Iterate via indices
for i in array.indices {
print(array[i])
}
// Copies are eager (no copy-on-write)
var copy = array
copy[0] = 99
// array[0] is still 4InlineArray vs Array
| Characteristic | InlineArray | Array |
| Storage | Inline (stack or enclosing type) | Heap-allocated buffer |
| Size | Fixed at compile time | Dynamic |
| Copy semantics | Eager (full copy) | Copy-on-write |
| Reference counting | None | Yes (buffer reference) |
| Exclusivity checks | None | Yes |
| Append/remove | Not supported | Supported |
Span Family
Span (Read-Only)
Provides safe, direct access to contiguous typed memory. Non-escapable -- cannot outlive the source.
let array = [1, 2, 3, 4]
let span = array.span // Span<Int>
// Access elements
let first = span[0]
let count = span.count
// Iterate
for element in span {
print(element)
}MutableSpan
Mutable access to contiguous storage:
var array = [1, 2, 3, 4]
array.withMutableSpan { span in
for i in span.indices {
span[i] *= 2
}
}
// array is now [2, 4, 6, 8]RawSpan
Untyped byte-level access for binary data:
let data = Data([0xFF, 0x00, 0xAB, 0xCD])
let rawSpan = data.bytes // RawSpan over the bytes
let value = rawSpan.unsafeLoadUnaligned(as: UInt8.self) // loading integers is safeFor writing into uninitialized memory, OutputRawSpan builds a Data incrementally with no manual offset tracking (WWDC25 312):
let output = Data(rawCapacity: totalBytes) { outputSpan in
// append bytes; outputSpan.count tracks what's been written
}For binary parsers, Apple ships the open-source swift-binary-parsing library (ParserSpan, overflow-safe parsing initializers by signedness/bit-width/byte-order, validating parsers for RawRepresentable) — already used inside Apple (WWDC25 312).
UTF8Span
Specialized for safe and efficient Unicode processing of UTF-8 encoded text.
Safety Constraints
Non-Escapable: Cannot Return from Functions
Span has a lifetime dependency on the container it was derived from. It cannot be returned:
// ❌ Wrong -- Span cannot escape the function
func getSpan() -> Span<UInt8> {
let array: [UInt8] = Array(repeating: 0, count: 128)
return array.span // Compiler error
}
// ✅ Right -- process within the same scope
func processData(_ array: [UInt8]) {
let span = array.span
// Use span here
let sum = span.reduce(0, +)
}Invalidation on Mutation
Modifying the source container invalidates any existing span:
// ❌ Wrong -- span is invalidated after mutation
var array = [1, 2, 3]
let span = array.span
array.append(4) // Invalidates span
// let x = span[0] // Undefined behavior
// ✅ Right -- re-acquire span after mutation
var array = [1, 2, 3]
array.append(4)
let span = array.span // Fresh span after mutation
let x = span[0] // SafePerformance Considerations
When InlineArray Wins
- Small, fixed-size data (e.g., color components, matrix rows, coordinate tuples)
- Hot loops where heap allocation / ARC overhead is measurable
- Embedded Swift or contexts with no allocator
- Struct fields that should be stored inline rather than behind a pointer
When Array Wins
- Collection size is unknown or variable
- Collection is large and frequently shared (COW avoids full copies)
- Collection is passed across module boundaries where dynamic sizing is needed
When Span Wins Over UnsafePointer
- All new code that needs contiguous memory access -- Span provides the same performance with compile-time safety
- Binary parsing where you read structured data from a byte buffer
- Algorithm implementations that operate on slices of memory
When UnsafePointer Is Still Needed
- C interop requiring raw pointer parameters
- Legacy APIs that predate Span adoption
- Interfacing with system calls that take pointer arguments
When to Use / When NOT to Use
Use InlineArray When
- You know the exact element count at compile time
- You need zero heap allocation (stack storage)
- The collection is small (< ~64 elements as a guideline)
- You modify in place but rarely copy the whole collection
- You are writing performance-critical or embedded code
Do NOT Use InlineArray When
- The collection size varies at runtime
- The collection is large and frequently copied (no COW means expensive copies)
- You need to append, insert, or remove elements
- You benefit from sharing storage across variables
Use Span When
- You need fast, safe, read-only access to contiguous memory
- You want to replace
UnsafeBufferPointerwith a safe alternative - You are processing data in place without needing to escape the reference
- You are implementing high-performance algorithms on collection storage
Do NOT Use Span When
- You need to store the reference for later use (Span is non-escapable)
- You need to pass memory access across async boundaries
- You need mutable access (use
MutableSpaninstead) - C interop requires actual
UnsafePointerarguments
Review Checklist
InlineArray
- Count is a compile-time constant (value generic), not a runtime variable
- Collection size is genuinely fixed and will not need dynamic resizing
- No code attempts to
append,insert, orremoveelements - Copies are intentional -- each assignment copies all elements eagerly
- Large
InlineArrayvalues are not copied in hot loops (pass byinoutor reference) MemoryLayoutis verified if precise byte layout matters (e.g., GPU buffers, file formats)
Span
- Span is never returned from a function or stored in a property
- Span is never captured in an escaping closure
- Source container is not mutated while a span is in use
- Span is re-acquired after any mutation to the source
- Correct span variant is used:
Span(read),MutableSpan(write),RawSpan(bytes) UnsafeBufferPointeris only used where C interop requires it; preferSpanotherwise
General Performance
- Profile before optimizing -- confirm heap allocation or ARC is the actual bottleneck
- Small fixed collections use
InlineArrayinstead ofArrayin measured hot paths Spanis used instead ofUnsafeBufferPointerfor safe contiguous access- No premature optimization --
Arrayis correct default for most code
What the payoff can look like when profiling confirms the bottleneck — Apple's QOI-parser case study (WWDC25 312): preallocating one buffer instead of ~1M transient arrays cut execution time over 50%; adopting InlineArray + RawSpan/OutputRawSpan made it another 6× faster by eliminating all retain/release traffic. See swift-performance.md for the full cost model (calls, copying, generics/existentials, closures, noncopyable ownership) and the profiling-symptom table.
References
- swift-performance.md (this skill) — the Swift cost model: allocation, ARC, exclusivity, dispatch,
~Copyableownership - Swift Standard Library - InlineArray
- Swift Standard Library - Span
- Value Generics in Swift
- SE-0453: Vector (InlineArray)
- SE-0447: Span
- WWDC25 — Improve memory usage and performance with Swift
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

