High-performance interned string type for Unity/C#. Ensures one shared Str instance per unique text for ultra-fast equality checks, thread-safe access, and built-in pool statistics.Str is a lightweight, production-ready interned string implementation for Unity/C#. It turns frequently used identifiers (keys, tags, event names, type IDs) into shared Str objects stored in a global table. For the same input text, Str.Create(string) always returns the same Str instance, which makes comparisons very fast and predictable in hot paths.- String interning (shared instances). Str.Create(string) returns one shared Str object per unique string value. - Fast equality checks. Compare Str instances directly instead of repeating ordinal string comparisons. - Thread-safe access. Uses ReaderWriterLockSlim: many readers at once, exclusive writes only when a new string is added. - Convenient empty handling. Str.empty is a shared empty value, and Str.IsNullOrEmpty(Str) checks null or empty quickly. - Pool metrics for profiling. Track growth with strCount, symbolsCount, and maxStrLength to spot unbounded string usage early. - Sorting support. Implements IComparable for deterministic ordering when needed.Typical Use Cases IDs and names in gameplay/engine code (states, actions, events, message types) Dictionary keys in hot paths (state machines, behavior trees, ECS-like code) Tags, feature flags, and protocol identifiersBest Practices: Str is intended for stable identifiers, not unbounded user input. Because the intern table is global and persistent, avoid interning values like GUIDs, chat messages, or large dynamic strings. Use Str.String/ToString() mainly at boundaries (UI, logs, serialization).If your project relies heavily on string keys, Str offers a fast, clean alternative to raw string values while keeping your code readable and profiling-friendly.AI disclosure: Documentation PDF includes sections drafted with ChatGPT and edited by the author. All runtime code is original and human-written. No third-party copyrighted content used.




