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
- Distinctive: line 8
When writing code that involves string building, formatting, or rendering (especially in the TUI engine, logging, or event loops), you MUST …
- Distinctive: line 12
When building ANSI escape sequences
- Distinctive: line 13
When building strings in a 60 FPS event loop or render cycle
- Very specific: line 14
When using tracing::*! macros
- Very specific: line 19
Read the full Source of Truth at mod@crate::core::common::fast_strings#string-allocation-performance-strategy for detailed architectural …
- Very specific: line 27
format!/write!: - Always heap allocates (format!) OR uses heavy formatter overhead (write!). - Very specific: line 32
Use for custom types (like ANSI codes) that are serialized millions of times.
- Very specific: line 34
Use generate_impl_display_for_fast_stringify!
- Distinctive: line 37
Use for stack-allocated strings (16 bytes).
- Very specific: line 40
Warning: If text exceeds 16 bytes, it spills to the heap and incurs the cost of format!
- Very specific: line 43
Use for hot loops where the string is guaranteed to exceed 16 bytes (meaning inline_string!
≈ “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.
Files
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!orwrite!on aFormatter
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)
- Direct
push_str()- Zero overhead, direct memory copy. crate::format_no_alloc!- Zero heap allocations, reuses existing heap.FastStringify- Temporary heap allocation, completely bypassesFormatterstate machine.inline_string!- Stack allocated (16 bytes), but dynamically spills to the heap if exceeded.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
Formatterstate machine by pushing everything into a temporary heapStringand making ONEf.write_str()call. - Use
generate_impl_display_for_fast_stringify!to auto-generate theDisplayblock.
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.
In this repository30 other files it gives its agents.
- .agents/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- build-infra/AGENTS.mdAGENTS.md
- rust-analyzer-mcp-server/AGENTS.mdAGENTS.md
- task/AGENTS.mdAGENTS.md
- llms.txtllms.txt
- analyze-log-filesSkill
- analyze-performanceSkill
- audit-taskSkill
- batch-refactor-with-sub-agentsSkill
- check-bounds-safetySkill
- check-code-qualitySkill
- check-test-coverageSkill
- code-reviewSkill
- concurrency-safetySkill
- create-commit-messageSkill
- create-prSkill
- design-philosophySkill
- fix-issueSkill
- merge-prSkill
- organize-modulesSkill
- organize-testsSkill
- release-crateSkill
- remove-crate-prefixSkill
- review-prSkill
- run-clippySkill
- safe-renamingSkill
- test-cross-platformSkill
- write-documentationSkill
- write-structured-tracingSkill
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.

