Skip to content
Skills Library
Programming · Building & coding

fast-string-allocations

/fast-string-allocations

Zero-allocation string building strategies. Use when formatting strings, generating ANSI codes, or writing hot loops to avoid heap allocations and Formatter state machine overhead.

Licence
Apache-2.0
Last repository change
17.10.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 17.10.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What it does and when to use it

Zero-allocation string building strategies. Use when formatting strings, generating ANSI codes, or writing hot loops to avoid heap allocations and Formatter state machine overhead.

Original author description

Zero-allocation string building strategies. Use when formatting strings, generating ANSI codes, or writing hot loops to avoid heap allocations and Formatter state machine overhead.

How it works

  1. When to Use
  2. Core Strategy
  3. Implementation Guidelines
Original SKILL.md headings · 43 lines, 309 words
SKILL.md preview
---
name: fast-string-allocations
description: Zero-allocation string building strategies. Use when formatting strings, generating ANSI codes, or writing hot loops to avoid heap allocations and Formatter state machine overhead.
---

# Fast String Allocations & Zero-Overhead Formatting

When writing code that involves string building, formatting, or rendering (especially in the TUI engine, logging, or event loops), you MUST adhere to the codebase's strict zero-allocation architecture.

## When to Use

- When building ANSI escape sequences
- When building strings in a 60 FPS event loop or render cycle
- When using `tracing::*!` macros
- Whenever you are tempted to use `format!` or `write!` on a `Formatter`

## Core Strategy

Read the full Source of Truth at `mod@crate::core::common::fast_strings#string-allocation-performance-strategy` for detailed architectural constraints.

### Performance Hierarchy (Fastest to Slowest)

1. **Direct `push_str()`** - Zero overhead, direct memory copy.
2. **`crate::format_no_alloc!`** - Zero heap allocations, reuses existing heap.
3. **`FastStringify`** - Temporary heap allocation, completely bypasses `Formatter` state machine.
4. **`inline_string!`** - Stack allocated (16 bytes), but dynamically spills to the heap if exceeded.
5. **`format!` / `write!`** - Always heap allocates (`format!`) OR uses heavy formatter overhead (`write!`). Avoid in hot paths.

## Implementation Guidelines

### 1. The `FastStringify` Trait
Use for custom types (like `ANSI` codes) that are serialized millions of times.
- Bypasses the expensive `Formatter` state machine by pushing everything into a temporary heap `String` and making ONE `f.write_str()` call.
- Use `generate_impl_display_for_fast_stringify!` to auto-generate the `Display` block.

### 2. The `inline_string!` Macro
Use for stack-allocated strings (16 bytes).
- Drop-in replacement for `format!`.
- The primary use case is the core Editor Component and `tracing::*!` macros.
- **Warning:** If text exceeds 16 bytes, it spills to the heap and incurs the cost of `format!`.

### 3. The `format_no_alloc!` Macro
Use for hot loops where the string is guaranteed to exceed 16 bytes (meaning `inline_string!` would spill).
- Hoist a `String::with_capacity(N)` outside the loop.
- Pass the hoisted string into the macro inside the loop to clear and write into the existing capacity.
- Zero allocations per tick.

Versions

The database has no other skills named fast-string-allocations.

Database snapshot: 13.11.2026 · package version 4cdf01162870 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100memory-allocation-analyzer
    Find unnecessary heap allocations in C# hot paths — LINQ in loops, boxing, closures, string concatenation, params arrays, async state machines — and rewrite to reduce GC pressure. Use this skill whenever the user wants to reduce allocations, cut GC pressure, find…
  • 100heaptrack
    Use when tracking heap allocations on Linux with heaptrack: allocation hotspots, peak heap, temporary allocations, leaks, or a diff of two runs via heaptrack_print. Not for heap errors.
  • 90review-perf
    Use when reviewing changes for performance, such as complexity regressions, repeated work, avoidable allocations, or hot-path inefficiencies.
  • 100heaptrack
    heaptrack memory profiler skill for Linux. Use when tracking heap allocations, finding memory leaks, measuring peak heap usage, identifying allocation hotspots, or comparing allocation behaviour between runs. Activates on queries about heaptrack, heap profiling, memory…
  • 100go-performance
    Use when profiling, benchmarking, or optimizing Go code — includes the measure-first methodology, the pprof-driven decision tree (which symptom maps to which fix), allocation reduction, capacity hints, hot-path patterns (strconv vs fmt, repeated string→byte conversions,…
  • 100go-performance
    Use when profiling, benchmarking, or optimizing Go code — includes the measure-first methodology, the pprof-driven decision tree (which symptom maps to which fix), allocation reduction, capacity hints, hot-path patterns (strconv vs fmt, repeated string→byte conversions,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.