agentleFS
r3bl-orgr3bl-org/r3bl-open-core/.agents/skills/fast-string-allocations/SKILL.md

fast-string-allocations

Skill486 starsChanged 15 days agoApache-2.0View on GitHub

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.

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 4 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When writing code that involves string building, formatting, or rendering (especially in the TUI engine, logging, or event loops), you MUST …

    line 8
  2. Distinctive:

    When building ANSI escape sequences

    line 12
  3. Distinctive:

    When building strings in a 60 FPS event loop or render cycle

    line 13
  4. Very specific:

    When using tracing::*! macros

    line 14
  5. Very specific:

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

    line 19
  6. Very specific:

    format! / write!: - Always heap allocates (format!) OR uses heavy formatter overhead (write!).

    line 27
  7. Very specific:

    Use for custom types (like ANSI codes) that are serialized millions of times.

    line 32
  8. Very specific:

    Use generate_impl_display_for_fast_stringify!

    line 34
  9. Distinctive:

    Use for stack-allocated strings (16 bytes).

    line 37
  10. Very specific:

    Warning: If text exceeds 16 bytes, it spills to the heap and incurs the cost of format!

    line 40
  11. Very specific:

    Use for hot loops where the string is guaranteed to exceed 16 bytes (meaning inline_string!

    line 43

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.