Performance Hints (PerformanceHints)
Overview
The PerformanceHints diagnostic group provides opt-in guidance for identifying language constructs and code patterns that carry non-obvious runtime performance costs. The diagnostics are intended to help developers writing performance-critical code make informed decisions about the abstractions they use and to surface hidden costs that may not be apparent from the source code alone to a non-expert Swift programmer.
This diagnostic group is off by default. It can be enabled as warnings with -Wwarning PerformanceHints, or escalated to errors with -Werror PerformanceHints.
Sub-groups
The PerformanceHints group contains the following sub-groups, each of which can also be enabled or controlled independently:
Existential Types and Performance (ExistentialType): Warns on use of existential types (
any Protocol), which incur heap allocation, reference counting, exclusivity enforcement, and dynamic dispatch overhead.Implicit Copy On Return (ReturnTypeImplicitCopy): Warns when functions or closures return
ArrayorDictionaryvalues, which leads to implicit heap-allocated copies of the collections.Untyped throws (UntypedThrows): Warns on untyped
throwsdeclarations, where the use ofany Errorincurs a heap allocation on eachthrow.
For example, to enable only the UntypedThrows checks as warnings:
-Wwarning UntypedThrowsOr to enable all performance hints as errors but keep UntypedThrows as a warning:
-Werror PerformanceHints -Wwarning UntypedThrowsSee Also
@dynamicCallable implementation requirements (DynamicCallable)Add @preconcurrency import (AddPreconcurrencyImport)Always enabled availability domains (AlwaysAvailableDomain)Argument matching for trailing closures (TrailingClosureMatching)Calling a mutating async actor-isolated method (ActorIsolatedMutatingAsync)Calling an actor-isolated method from a synchronous nonisolated context (ActorIsolatedCall)Captures in a `@Sendable` closure (SendableClosureCaptures)Compilation caching (CompilationCaching)Conforming to `StringInterpolationProtocol` (StringInterpolationConformance)Conversion from `@isolated(any)` function type to synchronous function type (ConversionFromIsolatedAnyToSynchronous)Cross-isolation data race (RegionIsolationCrossIsolationDataRace)Deprecated declaration warnings (DeprecatedDeclaration)Deprecated implementation-only imports (ImplementationOnlyDeprecated)Dynamic exclusivity (DynamicExclusivity)Embedded Swift language restrictions (EmbeddedRestrictions)