Agent skill

Corvus Low Alloc Data Structures

by corvus-dotnet in corvus-dotnet/Corvus.JsonSchema

Use and extend the custom low-allocation data structures in Corvus.JsonSchema.

Apache-2.0Auto-check passed

Install Corvus Low Alloc Data Structures

skills CLI
$ npx skills add corvus-dotnet/Corvus.JsonSchema --skill corvus-low-alloc-data-structures -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install corvus-dotnet/Corvus.JsonSchema corvus-low-alloc-data-structures --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/corvus-dotnet/Corvus.JsonSchema.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/corvus-low-alloc-data-structures .claude/skills/corvus-low-alloc-data-structures && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
corvus-low-alloc-data-structures
GitHub stars
199
Token cost
~2.6k tokens
SKILL.md length
763 words
Files
1
Skills in repo
26
Repo updated
First seen
Licence
Apache-2.0

At a glance

Use and extend the custom low-allocation data structures in Corvus.JsonSchema.

  • Works in 6 steps: Accept initial storage as constructor… → Define stack-alloc size constants on the… → Implement IDisposable to return any… → …
  • : choosing which stack-allocated collection to use
  • SKILL.md covers Collection Selection Guide, Utf8KeyHashSet —…, UniqueItemsHashSet — Schema… and ValueListBuilder —…, plus 8 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Corvus Low Alloc Data Structures is an agent skill from corvus-dotnet/Corvus.JsonSchema. Use and extend the custom low-allocation data structures in Corvus.JsonSchema. Covers ref-struct collections (Utf8KeyHashSet, UniqueItemsHashSet, ValueListBuilder, ValueStringBuilder, Utf8ValueStringBuilder, BitStack, Sequence), SIMD scanning patterns, bit manipulation tricks, and happy-path optimisations like lazy error messages. USE FOR: choosing which stack-allocated collection to use, writing new ref-struct types, adding SIMD-accelerated code paths, understanding branchless techniques, writing validation code…

Its SKILL.md is about 2.6k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

The repository describes itself as: Support for Json Schema validation and entity generation. The licence is Apache-2.0.

When your agent uses it

  • : choosing which stack-allocated collection to use
  • Writing new ref-struct types
  • Adding SIMD-accelerated code paths
  • Understanding branchless techniques

Example prompts

  • “/corvus-low-alloc-data-structures”

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Accept initial storage as constructor parameters — let the caller stackalloc the initial buffers
  2. Define stack-alloc size constants on the type (e.g., StackAllocBucketSize)
  3. Implement IDisposable to return any ArrayPool-rented overflow buffers
  4. Use MemoryMarshal.Write/Read with [MethodImpl(AggressiveInlining)] for packed entries
  5. Growth via ArrayPool.Shared.Rent() with geometric (2×) sizing
  6. Return old rented buffer before taking a new one during growth

What it can do on your machine

Read from SKILL.md and the folder at commit b9e3040. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are csharp).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Corvus Low Alloc Data Structures loads about 2.6k tokens when it runs. Until then it costs about 181 tokens; SKILL.md has 763 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~181
When it runs · the whole SKILL.md, loaded when a task matches
~2.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from corvus-dotnet/Corvus.JsonSchema at commit b9e3040, republished under its Apache-2.0 licence (© corvus-dotnet). 763 words, ~2,555 tokens.

Download SKILL.mdSave it as .claude/skills/corvus-low-alloc-data-structures/SKILL.md (or your agent's skills folder).
name
corvus-low-alloc-data-structures
description
Use and extend the custom low-allocation data structures in Corvus.JsonSchema. Covers ref-struct collections (Utf8KeyHashSet, UniqueItemsHashSet, ValueListBuilder, ValueStringBuilder, Utf8ValueStringBuilder, BitStack, Sequence), SIMD scanning patterns, bit manipulation tricks, and happy-path optimisations like lazy error messages. USE FOR: choosing which stack-allocated collection to use, writing new ref-struct types, adding SIMD-accelerated code paths, understanding branchless techniques, writing validation code that avoids allocation on success. DO NOT USE FOR: basic buffer allocation patterns (use corvus-buffer-and-pooling), document model (use corvus-parsed-documents-and-memory).

Low-Allocation Data Structures

Collection Selection Guide

Choose the right collection based on your need:

NeedTypeLocationHeap allocation?
Deduplicate UTF-8 keysUtf8KeyHashSetCommon/Utf8KeyHashSet.csNo (stack + ArrayPool fallback)
Check JSON array uniquenessUniqueItemsHashSetJsonSchema/Internal/UniqueItemsHashSet.csNo (stack + ArrayPool fallback)
Growable list (small)ValueListBuilder<T>System.Private.CoreLib/.../ValueListBuilder.csNo (stack + ArrayPool fallback)
Build a UTF-16 stringValueStringBuilderCommon/src/System/Text/ValueStringBuilder.csNo (stack + ArrayPool fallback)
Build a UTF-8 stringUtf8ValueStringBuilderCommon/src/System/Text/Utf8ValueStringBuilder.csNo (stack + ArrayPool fallback)
Track nesting depthBitStackBitStack.csNo (ulong for ≤64 levels)
Return singleton/multi valueSequenceCorvus.Text.Json.Jsonata/Sequence.csNo for singletons; ArrayPool for multi
Sliding-window byte bufferArrayBufferCommon/src/System/Net/ArrayBuffer.csArrayPool backed

All ref struct types must be disposed (they implement IDisposable to return pooled memory).

Utf8KeyHashSet — Stack-Allocated UTF-8 Hash Set

A ref struct separate-chaining hash set for UTF-8 byte-string keys. Used for property deduplication and JSONata merge operations.

csharp
// Typical usage — stack-allocate initial buffers, dispose to return any rented overflow
Span<int> buckets = stackalloc int[Utf8KeyHashSet.StackAllocBucketSize];
Span<byte> entries = stackalloc byte[Utf8KeyHashSet.StackAllocEntrySize];
Span<byte> keyBuffer = stackalloc byte[Utf8KeyHashSet.StackAllocKeyBufferSize];

using Utf8KeyHashSet hashSet = new(estimatedPropertyCount, buckets, entries, keyBuffer);
bool added = hashSet.Add(utf8Key);
Internal design
  • Entries are packed as 20-byte binary records: Next(4) + BufOffset(4) + Length(4) + HashCode(8)
  • Packed with MemoryMarshal.Write/Read and [MethodImpl(AggressiveInlining)]
  • Growth uses a small prime table (3, 7, 11, 17, ... 521) — avoids HashHelpers dependency
  • Falls back to ArrayPool only when stack buffers overflow
  • Stack alloc sizes: buckets = 64 ints (256 bytes), entries = 512 bytes, key buffer = 512 bytes
When to use
  • Property name deduplication in JSON object processing
  • Merge operations in JSONata where duplicate keys must be detected
  • Any scenario needing set membership testing on UTF-8 byte sequences without allocation

UniqueItemsHashSet — Schema Validation Hash Set

Same architectural pattern as Utf8KeyHashSet, but specifically for JSON Schema uniqueItems keyword validation. Compares full JSON element values (not just strings).

ValueListBuilder<T> — Stack-Backed Generic List

Ported from dotnet/runtime's internal type. A ref struct list that starts on the stack and overflows to ArrayPool.

csharp
Span<int> initialBuffer = stackalloc int[16];
ValueListBuilder<int> list = new(initialBuffer);

try
{
    list.Append(42);
    list.Append(99);
    ReadOnlySpan<int> items = list.AsSpan();
}
finally
{
    list.Dispose();  // returns any rented array
}
Key behaviours
  • Initial buffer is the caller's stackalloc span — zero heap allocation for small lists
  • Grows with 2× doubling via ArrayPool<T>.Shared.Rent()
  • Dispose() returns the rented array and clears references if T is a reference type
  • Used in YAML writing (Utf8YamlWriter._contextStack), JSON parsing, and path navigation

ValueStringBuilder / Utf8ValueStringBuilder

Two parallel ref struct string builders — one for char (UTF-16), one for byte (UTF-8). Both follow the stackalloc → ArrayPool growth pattern.

csharp
// UTF-16 string building
Span<char> initialChars = stackalloc char[JsonConstants.StackallocCharThreshold];
ValueStringBuilder sb = new(initialChars);
try
{
    sb.Append("hello");
    sb.Append(' ');
    sb.Append("world");
    return sb.ToString();
}
finally
{
    sb.Dispose();
}

// UTF-8 string building
Span<byte> initialBytes = stackalloc byte[JsonConstants.StackallocByteThreshold];
Utf8ValueStringBuilder usb = new(initialBytes);
try
{
    usb.Append("hello"u8);
    ReadOnlySpan<byte> result = usb.AsSpan();
}
finally
{
    usb.Dispose();
}
Differences
FeatureValueStringBuilderUtf8ValueStringBuilder
Element typecharbyte
Double-dispose detectionNoYes (_pos = -1 on dispose)
Interpolation supportAppendSpanFormattableNo

BitStack — Allocation-Free Nesting Tracker

Tracks JSON object/array nesting using bit manipulation on a ulong. No allocation for the first 64 levels.

csharp
BitStack stack = default;
stack.PushTrue();   // entering an object
stack.PushFalse();  // entering an array
bool wasObject = stack.Pop();  // leaving — returns true if it was an object
Internal design
  • First 64 levels: single ulong _allocationFreeContainer with shift/mask operations
  • Beyond 64 levels: falls back to heap-allocated int[] (extremely rare in practice)
  • Div32Rem uses & 31 instead of % 32 for the array path

Sequence — 32-Byte Inline Tagged Union (JSONata)

The JSONata evaluator's primary result type. Stores singleton values inline without allocation.

Layout (32 bytes):
  object? payload     (8 bytes)  — reference-type backing for multi-value
  double rawValue     (8 bytes)  — inline double storage
  JsonElement single  (12 bytes) — inline singleton element
  int countAndTag     (4 bytes)  — bits 0-23: count, bits 24-31: tag

Tags: Undefined=0, Singleton=1, Multi=2, Lambda=3, Regex=4, RawDouble=7, Tuple=9.

  • Singleton: zero heap allocation — the JSON element is stored inline in the struct
  • Multi: rents from ArrayPool<JsonElement> — must be disposed
  • A single JSON element evaluation produces a Singleton sequence with zero allocation
Show full SKILL.md (295 more words)Show less

SIMD Scanning Patterns

Vector<byte> parallel scanning (netstandard path)

On platforms without SearchValues<byte>, the codebase uses explicit SIMD:

csharp
if (Vector.IsHardwareAccelerated && length >= Vector<byte>.Count * 2)
{
    Vector<byte> vQuote = new((byte)'"');
    Vector<byte> vBackslash = new((byte)'\\');
    Vector<byte> vControlMax = new(0x1F);

    Vector<byte> vData = Unsafe.ReadUnaligned<Vector<byte>>(
        ref Unsafe.AddByteOffset(ref searchSpace, index));

    var vMatches = Vector.BitwiseOr(
        Vector.BitwiseOr(
            Vector.Equals(vData, vQuote),
            Vector.Equals(vData, vBackslash)),
        Vector.LessThan(vData, vControlMax));
}

Scans 16–32 bytes simultaneously for quotes, backslashes, or control characters.

De Bruijn bit scanning

Finding the first set bit in a SIMD match result:

csharp
ulong powerOfTwoFlag = match ^ (match - 1);    // isolate lowest set bit
return (int)((powerOfTwoFlag * XorPowerOfTwoToHighByte) >> 57);

O(1) branchless lookup using a precomputed De Bruijn constant.

8× unrolled SIMD count

SpanHelper.Count in the source generator processes 8 × Vector<T>.Count elements per iteration for counting matching items in spans.

Bit Manipulation Techniques

Branchless token type classification
csharp
public static bool IsTokenTypePrimitive(JsonTokenType tokenType) =>
    (tokenType - JsonTokenType.String) <= (JsonTokenType.Null - JsonTokenType.String);

Single unsigned subtraction + comparison replaces a multi-branch switch.

Bit-packed struct fields

DbRow (12 bytes) packs token type, location, size, child count, and flags into 3 uint/int fields using bit shifts and masks. The top nibble of the third field encodes JsonTokenType.

Happy-Path Optimisations

Lazy error messages in schema validation
csharp
private static readonly JsonSchemaMessageProvider ExpectedDate =
    static (buffer, out written) => { /* format error message only when called */ };

On the success path, EvaluatedKeyword(true, ...) records success without touching the message provider. Error strings are only materialised on failure.

Lazy SR (string resources)

ResourceManager is only created on first exception throw — UsingResourceKeys() returns early with the key itself when trimming is active.

CodeGenThrowHelper

Throw helpers set Exception.Source to a key instead of formatting a message string. The actual message is only looked up if the exception is caught and displayed.

Creating New ref struct Collections

When adding a new ref struct collection, follow these patterns:

  1. Accept initial storage as constructor parameters — let the caller stackalloc the initial buffers
  2. Define stack-alloc size constants on the type (e.g., StackAllocBucketSize)
  3. Implement IDisposable to return any ArrayPool-rented overflow buffers
  4. Use MemoryMarshal.Write/Read with [MethodImpl(AggressiveInlining)] for packed entries
  5. Growth via ArrayPool<T>.Shared.Rent() with geometric (2×) sizing
  6. Return old rented buffer before taking a new one during growth

Cross-References

  • For the basic stackalloc/rent pattern and pooling tiers, see corvus-buffer-and-pooling
  • For document memory model, see corvus-parsed-documents-and-memory
  • For full conventions, see .github/copilot-instructions.md

© corvus-dotnet, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/corvus-low-alloc-data-structures of corvus-dotnet/Corvus.JsonSchema.

Open the folder on GitHubat commit b9e3040

Compare with similar skills

Corvus Low Alloc Data Structures next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Corvus Low Alloc Data Structures compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Corvus Low Alloc Data Structures this skillcorvus-dotnet/Corvus.JsonSchema199—~2.6kAutomated safety check: PassApache-2.0
Structured Datathedaviddias/Front-End-Checklist74k—~420Automated safety check: PassMIT
Bio Structural Biology Modern Structure PredictionFreedomIntelligence/OpenClaw-Medical-Skills3.1k1 repos~2.5kAutomated safety check: PassNone
Agent Resource Allocatorruvnet/ruflo74k2 repos~4.9kAutomated safety check: PassMIT
List Structurethedaviddias/Front-End-Checklist74k—~438Automated safety check: PassMIT
Bio Structural Biology Structure IoGPTomics/bioSkills1.2k1 repos~4kAutomated safety check: PassMIT

Similar skills

  • Structured Data

    thedaviddias/Front-End-Checklist

    A skill your agent uses when auditing metadata, crawlability, structured data, or indexability related to Add structured data markup.

    74k GitHub stars~420 tokensUpdated yesterday
    Marketing & SEOAuto-check passed
  • Bio Structural Biology Modern Structure Prediction

    FreedomIntelligence/OpenClaw-Medical-Skills

    Predict protein structures using modern ML models including AlphaFold3, ESMFold, Chai-1, and Boltz-1.

    3.1k GitHub starsUsed in 1 repo~2.5k tokens
    Research & ScienceAuto-check passed
  • Agent skill for resource-allocator - invoke with $agent-resource-allocator

    74k GitHub starsUsed in 2 repos~4.9k tokens
    Auto-check passed
  • List Structure

    thedaviddias/Front-End-Checklist

    A skill your agent uses when reviewing rendered HTML, interactive components, or design-system patterns related to Use correct list structure.

    74k GitHub stars~438 tokensUpdated yesterday
    Frontend & DesignAuto-check passed
  • Reads, writes, downloads, and converts macromolecular structures with Biopython Bio.PDB.

    1.2k GitHub starsUsed in 1 repo~4k tokens
    Research & ScienceAuto-check passed
  • Navigate the Bio.PDB SMCRA hierarchy (Structure-Model-Chain-Residue-Atom) safely, surfacing the heterogeneity it hides by default.

    1.2k GitHub starsUsed in 1 repo~3.7k tokens
    Research & ScienceAuto-check passed

More from corvus-dotnet/Corvus.JsonSchema

All 26 skills in this repo
  • Corvus Analyzers

    corvus-dotnet/Corvus.JsonSchema

    Understand and work with the Roslyn analyzers shipped with Corvus.Text.Json.

    199 GitHub stars~876 tokensUpdated today
    Auto-check passed
  • Corvus Benchmarks

    corvus-dotnet/Corvus.JsonSchema

    Run, interpret, and maintain BenchmarkDotNet benchmarks for JSON Schema validation and query languages.

    199 GitHub stars~1.2k tokensUpdated today
    Auto-check passed
  • Corvus Bowtie Testing

    corvus-dotnet/Corvus.JsonSchema

    Test Corvus.JsonSchema against the JSON Schema Test Suite using Bowtie, the cross-implementation meta-validator.

    199 GitHub stars~1.4k tokensUpdated today
    Auto-check passed
  • Corvus Buffer And Pooling

    corvus-dotnet/Corvus.JsonSchema

    Write allocation-efficient buffer code in Corvus.JsonSchema using the codebase's established three-tier pooling pattern: stackalloc → ArrayPool → ThreadStatic caches.

    199 GitHub stars~2.9k tokensUpdated today
    Auto-check passed
  • Corvus Bytes To Bytes

    corvus-dotnet/Corvus.JsonSchema

    Eliminate hand-rolled POCO record<-document string seams — types/paths that materialize a managed string (or List<string/Dictionary) between a bytes SOURCE (a parsed UTF-8 body, a DB column, a…

    199 GitHub stars~3k tokensUpdated today
    Auto-check passed
  • Corvus Codegen

    corvus-dotnet/Corvus.JsonSchema

    Generate strongly-typed C from JSON Schema using the Roslyn source generator or the corvusjson CLI tool.

    199 GitHub stars~2.1k tokensUpdated today
    Auto-check passed

Questions about Corvus Low Alloc Data Structures

What does Corvus Low Alloc Data Structures do?

Use and extend the custom low-allocation data structures in Corvus.JsonSchema. JsonSchema.JsonSchema.

When should I use Corvus Low Alloc Data Structures?

Corvus Low Alloc Data Structures fits situations like: : choosing which stack-allocated collection to use; writing new ref-struct types; adding SIMD-accelerated code paths; understanding branchless techniques.

How do I install Corvus Low Alloc Data Structures in Claude Code?

Run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill corvus-low-alloc-data-structures -a claude-code`. Or copy the skill folder (.github/skills/corvus-low-alloc-data-structures in corvus-dotnet/Corvus.JsonSchema) into .claude/skills/corvus-low-alloc-data-structures in your project. Claude Code loads it when a task matches its description.

How do I install Corvus Low Alloc Data Structures in Codex?

Run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill corvus-low-alloc-data-structures -a codex`. Or copy the skill folder (.github/skills/corvus-low-alloc-data-structures in corvus-dotnet/Corvus.JsonSchema) into .agents/skills/corvus-low-alloc-data-structures in your project. Codex loads it when a task matches its description.

Can I use Corvus Low Alloc Data Structures in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill corvus-low-alloc-data-structures -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/corvus-low-alloc-data-structures, .gemini/skills/corvus-low-alloc-data-structures, .github/skills/corvus-low-alloc-data-structures and .opencode/skills/corvus-low-alloc-data-structures in your project.

What does Corvus Low Alloc Data Structures need to run?

SKILL.md names no scripts, command-line tools or credentials: Corvus Low Alloc Data Structures is instructions for the agent only.

Does Corvus Low Alloc Data Structures access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Corvus Low Alloc Data Structures safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Corvus Low Alloc Data Structures use?

Corvus Low Alloc Data Structures is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Corvus Low Alloc Data Structures use?

About 2.6k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Corvus Low Alloc Data Structures?

Skills that share tags, products or a category with Corvus Low Alloc Data Structures: Structured Data (thedaviddias/Front-End-Checklist, 74k stars), Bio Structural Biology Modern Structure Prediction (FreedomIntelligence/OpenClaw-Medical-Skills, 3.1k stars), Agent Resource Allocator (ruvnet/ruflo, 74k stars) and List Structure (thedaviddias/Front-End-Checklist, 74k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Corvus Low Alloc Data Structures?

corvus-dotnet (a GitHub organization) maintains it in corvus-dotnet/Corvus.JsonSchema, which has 199 GitHub stars. The repository holds 26 skills in this directory. The repository was last updated on October 8, 2026.

Source: corvus-dotnet/Corvus.JsonSchema on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.