Skip to content

Async and Thread Safety

axunonb edited this page May 17, 2022 · 3 revisions

SmartFormat makes heavy use of caching and object pooling for expensive operations, which both require static containers.

SmartFormatters and Parsers require one instance per thread.

Multi-Threading, async context

When instantiating SmartFormatters from different threads, SmartSettings.IsThreadSafeMode=true must be set (which is the default since v3.1.0), so that thread-safe containers are used. This brings an inherent performance penalty.

Note: Static Smart methods like Smart.Format(format, args) can be called in an async / multi-threaded context since v3.1.0.

Single-Threading

When instantiating SmartFormatters from a single thread, SmartSettings.IsThreadSafeMode=false should be set for avoiding the multithreading overhead and thus for best performance. This is the default.

Clone this wiki locally