Skip to content

Async and Thread Safety

axunonb edited this page Apr 29, 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, so that thread-safe containers are used. This brings an inherent performance penalty.

Note: The simplified Smart.Format(...) API overloads use a static SmartFormatter instance which is not thread-safe. Call Smart.CreateDefaultSmartFormat() to create a SmartFormatter with defaults.

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.

The static Smart.Format(...) API overloads are allowed here.

Clone this wiki locally