# \#optimizations

**URL:** https://forums.swift.org/tag/optimizations/239.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [ML/RL-guided optimization in SIL, prior discussions?](https://forums.swift.org/t/ml-rl-guided-optimization-in-sil-prior-discussions/88547)

<div class="topic-metadata">

**Author:** [@lucasly-ba](https://forums.swift.org/u/lucasly-ba)\
**Replies:** 0\
**Last updated:** [July 26, 2026, 10:44am UTC](https://forums.swift.org/t/ml-rl-guided-optimization-in-sil-prior-discussions/88547 "2026-07-26T10:44:56Z")

</div>

Hi all, I've been contributing to SILOptimizer and got curious about whether there's been any exploration of using ML/RL to guide optimization decisions in SIL, in the spirit of what Google's MLGO does for inlining and …

---

## [Unexpected ObjC bridging symbols emitted for pure-Swift final classes in Array/Set](https://forums.swift.org/t/unexpected-objc-bridging-symbols-emitted-for-pure-swift-final-classes-in-array-set/86693)

<div class="topic-metadata">

**Author:** [@sew](https://forums.swift.org/u/sew)\
**Replies:** 12\
**Last updated:** [May 30, 2026, 12:33pm UTC](https://forums.swift.org/t/unexpected-objc-bridging-symbols-emitted-for-pure-swift-final-classes-in-array-set/86693 "2026-05-30T12:33:07Z")

</div>

Hello everyone, In a large iOS codebase, I recently investigated a binary size regression caused by replacing an immutable struct backed by private reference storage with an equivalent immutable final class. I was able …

---

## [Swift mention in C++ safety post](https://forums.swift.org/t/swift-mention-in-c-safety-post/76091)

<div class="topic-metadata">

**Author:** [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Replies:** 5\
**Last updated:** [May 9, 2026, 4:02am UTC](https://forums.swift.org/t/swift-mention-in-c-safety-post/76091 "2026-05-09T04:02:33Z")

</div>

Chandler Carruth, of C++ and Carbon, recently blogged about the trend towards safety in languages, citing Swift and other safer languages a couple times. He links a recent google blog post that only showed a small regre…

---

## [I reimplemented Foundation's JSONEncoder and made it 33% faster using compile-time strategy dispatch](https://forums.swift.org/t/i-reimplemented-foundations-jsonencoder-and-made-it-33-faster-using-compile-time-strategy-dispatch/84195)

<div class="topic-metadata">

**Author:** [@couchdeveloper](https://forums.swift.org/u/couchdeveloper)\
**Replies:** 7\
**Last updated:** [January 19, 2026, 7:55am UTC](https://forums.swift.org/t/i-reimplemented-foundations-jsonencoder-and-made-it-33-faster-using-compile-time-strategy-dispatch/84195 "2026-01-19T07:55:19Z")

</div>

I recently explored whether Swift's type system and compiler could eliminate runtime overhead in encoding, and the results were surprising: a 33% performance improvement over Foundation's JSONEncoder using clean, maintai…

---

## [Optimization quirk with OrderedSet init](https://forums.swift.org/t/optimization-quirk-with-orderedset-init/83858)

<div class="topic-metadata">

**Author:** [@Dmitriy\_Ignatyev](https://forums.swift.org/u/Dmitriy_Ignatyev)\
**Replies:** 0\
**Last updated:** [December 28, 2025, 12:21am UTC](https://forums.swift.org/t/optimization-quirk-with-orderedset-init/83858 "2025-12-28T00:21:59Z")

</div>

I’m investigating the performance of OrderedSet initialization from Swift Collections and am seeing some surprising results. To keep things simple, let’s focus on creating an OrderedSet with one or two elements. There a…

---

## [Implementing optimization comments in \`indexstore-db\`?](https://forums.swift.org/t/implementing-optimization-comments-in-indexstore-db/80807)

<div class="topic-metadata">

**Author:** [@moshe-foreflight](https://forums.swift.org/u/moshe-foreflight)\
**Replies:** 2\
**Last updated:** [December 15, 2025, 5:23pm UTC](https://forums.swift.org/t/implementing-optimization-comments-in-indexstore-db/80807 "2025-12-15T17:23:39Z")

</div>

I'm looking to optimize performance of indexstore-db based on two FIXMEs in the code that appear in the code. I'm looking for advice on how to implement (or request help implementing) them. Goal: I would like to be ab…

---

## [Missed optimizations due to integer overflow checks](https://forums.swift.org/t/missed-optimizations-due-to-integer-overflow-checks/83698)

<div class="topic-metadata">

**Author:** [@ole](https://forums.swift.org/u/ole)\
**Replies:** 4\
**Last updated:** [December 14, 2025, 2:12pm UTC](https://forums.swift.org/t/missed-optimizations-due-to-integer-overflow-checks/83698 "2025-12-14T14:12:34Z")

</div>

I noticed that integer overflow checks in Swift sometimes cause Swift code to "miss out" on certain compiler optimizations that Clang or GCC perform for "equivalent" C/C++ code (equivalent, that is, if it weren't for the…

---

## [Nested InlineArray generates unnecessary copies](https://forums.swift.org/t/nested-inlinearray-generates-unnecessary-copies/83364)

<div class="topic-metadata">

**Author:** [@tgu](https://forums.swift.org/u/tgu)\
**Replies:** 3\
**Last updated:** [November 22, 2025, 11:12am UTC](https://forums.swift.org/t/nested-inlinearray-generates-unnecessary-copies/83364 "2025-11-22T11:12:05Z")

</div>

Hi, I was playing around with InlineArray and found out that this function func col(i: Int, v: InlineArray\<8, InlineArray\<10, Int\>\>) -\> InlineArray\<10, Int\> { \[v\[i\]\[0\], v\[i\]\[1\], v\[i\]\[2\], v\[i\]\[3\], v\[i\]\[4\], v\[i…

---

## [SE-0496: \`@inline(always)\` Attribute](https://forums.swift.org/t/se-0496-inline-always-attribute/82480)

<div class="topic-metadata">

**Author:** [@allevato](https://forums.swift.org/u/allevato)\
**Replies:** 23\
**Last updated:** [October 23, 2025, 1:11pm UTC](https://forums.swift.org/t/se-0496-inline-always-attribute/82480 "2025-10-23T13:11:49Z")

</div>

Hello, Swift community! The review of SE-0496: @inline(always) Attribute begins now and runs through October 16th, 2025. Reviews are an important part of the Swift evolution process. All review feedback should be eithe…

---

## [\[Accepted\] SE-0496: \`@inline(always)\` Attribute](https://forums.swift.org/t/accepted-se-0496-inline-always-attribute/82825)

<div class="topic-metadata">

**Author:** [@allevato](https://forums.swift.org/u/allevato)\
**Replies:** 0\
**Last updated:** [October 23, 2025, 1:11pm UTC](https://forums.swift.org/t/accepted-se-0496-inline-always-attribute/82825 "2025-10-23T13:11:30Z")

</div>

Hello, Swift community! The review of SE-0496: @inline(always) Attribute ended on October 16th. Feedback on this proposal was generally positive. There were some questions raised during the review about specific behavi…

---

## [Undefined symbols linker error at -Osize (App + Extensions linking against a shared framework)](https://forums.swift.org/t/undefined-symbols-linker-error-at-osize-app-extensions-linking-against-a-shared-framework/82111)

<div class="topic-metadata">

**Author:** [@chiragramani](https://forums.swift.org/u/chiragramani)\
**Replies:** 0\
**Last updated:** [September 12, 2025, 8:11pm UTC](https://forums.swift.org/t/undefined-symbols-linker-error-at-osize-app-extensions-linking-against-a-shared-framework/82111 "2025-09-12T20:11:45Z")

</div>

We’re running into an issue when sharing code with app extensions and the main app binary, both of which link against a common framework we call SharedKit (a framework that hosts a .dylib and wraps common libraries). W…

---

## [Is it safe to deinitialize() uninitialized memory if it was bound to a trivial type?](https://forums.swift.org/t/is-it-safe-to-deinitialize-uninitialized-memory-if-it-was-bound-to-a-trivial-type/81869)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 5\
**Last updated:** [August 29, 2025, 5:33pm UTC](https://forums.swift.org/t/is-it-safe-to-deinitialize-uninitialized-memory-if-it-was-bound-to-a-trivial-type/81869 "2025-08-29T17:33:59Z")

</div>

I have been reading related threads and I have seen it clearly stated in several places (for example here) that it is safe to skip the call to deinitialize() on memory if it is bound to a “trivial type”, which I understa…

---

## [Optimizing task switching in deeply-nested concurrent code](https://forums.swift.org/t/optimizing-task-switching-in-deeply-nested-concurrent-code/81415)

<div class="topic-metadata">

**Author:** [@JackMacWindows](https://forums.swift.org/u/JackMacWindows)\
**Replies:** 6\
**Last updated:** [August 1, 2025, 1:58am UTC](https://forums.swift.org/t/optimizing-task-switching-in-deeply-nested-concurrent-code/81415 "2025-08-01T01:58:19Z")

</div>

I'm working on writing a Lua interpreter in pure Swift, using structured concurrency to implement features like coroutines, as well as for data race safety, which is important for my use case as I want to avoid race cond…

---

## [Implementation technique of \`try\_fold()\`](https://forums.swift.org/t/implementation-technique-of-try-fold/81345)

<div class="topic-metadata">

**Author:** [@robin33n](https://forums.swift.org/u/robin33n)\
**Replies:** 2\
**Last updated:** [July 28, 2025, 4:52am UTC](https://forums.swift.org/t/implementation-technique-of-try-fold/81345 "2025-07-28T04:52:04Z")

</div>

I'm studying the technique for implementing something similar to Rust try\_fold(), which in un-optimised form should be the following. It incurs heavy overhead of copying collection. I'd like to know what is the way or wa…

---

## [How to implement a Swift analogue of \`benchmark::DoNotOptimize\`?](https://forums.swift.org/t/how-to-implement-a-swift-analogue-of-benchmark-donotoptimize/78241)

<div class="topic-metadata">

**Author:** [@\_ck512](https://forums.swift.org/u/_ck512)\
**Replies:** 1\
**Last updated:** [March 10, 2025, 2:02pm UTC](https://forums.swift.org/t/how-to-implement-a-swift-analogue-of-benchmark-donotoptimize/78241 "2025-03-10T14:02:46Z")

</div>

I would like to do some microbenchmarking in Swift. I have been using package-benchmark for this. It comes with a blackHole helper function that forces the compiler to assume that a variable is read and thus prevent dead…

---

## [Static member lookup performance / alternatives](https://forums.swift.org/t/static-member-lookup-performance-alternatives/78314)

<div class="topic-metadata">

**Author:** [@mikewoodworth](https://forums.swift.org/u/mikewoodworth)\
**Replies:** 3\
**Last updated:** [March 5, 2025, 9:58pm UTC](https://forums.swift.org/t/static-member-lookup-performance-alternatives/78314 "2025-03-05T21:58:44Z")

</div>

I have a hot loop in my code that needs to set a var to different values based on an argument (essentially using a switch statement as lookup). Because the value set is used elsewhere (and has a non-zero init time) I've …

---

## [Compiler optimization with computed properties](https://forums.swift.org/t/compiler-optimization-with-computed-properties/77861)

<div class="topic-metadata">

**Author:** [@giik](https://forums.swift.org/u/giik)\
**Replies:** 1\
**Last updated:** [February 13, 2025, 9:44pm UTC](https://forums.swift.org/t/compiler-optimization-with-computed-properties/77861 "2025-02-13T21:44:48Z")

</div>

If the body of a computed property references another computed property multiple times, are there any guarantees—and if yes, under what conditions—that the latter will be optimized to a singular local value computation t…

---

## [Why retain/release pair is not removed in this particular case?](https://forums.swift.org/t/why-retain-release-pair-is-not-removed-in-this-particular-case/77206)

<div class="topic-metadata">

**Author:** [@shivatinker](https://forums.swift.org/u/shivatinker)\
**Replies:** 6\
**Last updated:** [January 15, 2025, 9:56pm UTC](https://forums.swift.org/t/why-retain-release-pair-is-not-removed-in-this-particular-case/77206 "2025-01-15T21:56:59Z")

</div>

Hey there! I have some performance critical code in my project, and I noticed that 20-30% of the time on the hot path is spent on retain/release calls. I have reduced the example to this code: protocol P { func tak…

---

## [Pitch: Support LTO for Swift](https://forums.swift.org/t/pitch-support-lto-for-swift/67379)

<div class="topic-metadata">

**Author:** [@elsh](https://forums.swift.org/u/elsh)\
**Replies:** 27\
**Last updated:** [November 27, 2024, 5:06pm UTC](https://forums.swift.org/t/pitch-support-lto-for-swift/67379 "2024-11-27T17:06:37Z")

</div>

Introduction A Swift application often comprises a substantial number of modules, with instances of 200 or more modules not being uncommon, each with varying sizes. New features are continually integrated into Swift appl…

---

## [SIMD code won't produce \`zip2.8h\`, but \`zip1.8h\` works fine](https://forums.swift.org/t/simd-code-wont-produce-zip2-8h-but-zip1-8h-works-fine/75825)

<div class="topic-metadata">

**Author:** [@AlexanderM](https://forums.swift.org/u/AlexanderM)\
**Replies:** 5\
**Last updated:** [November 20, 2024, 7:26pm UTC](https://forums.swift.org/t/simd-code-wont-produce-zip2-8h-but-zip1-8h-works-fine/75825 "2024-11-20T19:26:02Z")

</div>

Hey there, I'm not sure if this is a compiler bug, or I'm holding it wrong. I can open a GitHub issue if needed. This simple function: /// A function which uses the \`zip1.8h\` ARM instruction to interleave the first ha…

---

## [How Much Can the Compiler Optimise This Function?](https://forums.swift.org/t/how-much-can-the-compiler-optimise-this-function/75497)

<div class="topic-metadata">

**Author:** [@ibex](https://forums.swift.org/u/ibex)\
**Replies:** 3\
**Last updated:** [October 21, 2024, 5:00pm UTC](https://forums.swift.org/t/how-much-can-the-compiler-optimise-this-function/75497 "2024-10-21T17:00:56Z")

</div>

How much can the compiler optimise the following function, which computes Int-division by subtraction? // Compute division by subtraction func div2 (\_ u: Int, \_ v: Int) -\> Int { assert (v \> 0) var q = 0 var …

---

## [What does ".island" suffix in symbol name mean?](https://forums.swift.org/t/what-does-island-suffix-in-symbol-name-mean/73105)

<div class="topic-metadata">

**Author:** [@kyounh12](https://forums.swift.org/u/kyounh12)\
**Replies:** 6\
**Last updated:** [September 3, 2024, 7:56pm UTC](https://forums.swift.org/t/what-does-island-suffix-in-symbol-name-mean/73105 "2024-09-03T19:56:02Z")

</div>

During my analysis of the binary size changes after compiling Swift source code, I discovered symbols with the ".island" suffix. I couldn't find meaningful information about this suffix through my search, so I decided to…

---

## [Crash during MergeFunctions pass](https://forums.swift.org/t/crash-during-mergefunctions-pass/72646)

<div class="topic-metadata">

**Author:** [@carlos42421](https://forums.swift.org/u/carlos42421)\
**Replies:** 1\
**Last updated:** [June 21, 2024, 3:04pm UTC](https://forums.swift.org/t/crash-during-mergefunctions-pass/72646 "2024-06-21T15:04:31Z")

</div>

Hiya, I seem to be getting a crash in the MergeFunctions pass during codegen... (lldb) bt \* thread #2, stop reason = hit program assert frame #0: 0x00007ff80b8e314a libsystem\_kernel.dylib\`\_\_pthread\_kill + 10 fr…

---

## [Specialised closures in an ABI-stable library](https://forums.swift.org/t/specialised-closures-in-an-abi-stable-library/67856)

<div class="topic-metadata">

**Author:** [@Karl](https://forums.swift.org/u/Karl)\
**Replies:** 3\
**Last updated:** [June 6, 2024, 8:29am UTC](https://forums.swift.org/t/specialised-closures-in-an-abi-stable-library/67856 "2024-06-06T08:29:34Z")

</div>

I'm working on a feature for a resilient library, that looks something like this: @frozen public struct Stream\<Source: IteratorProtocol\<Int\>\>: IteratorProtocol { public var source: Source @usableFromInline inter…

---

## [Casting/Type checking in Swift broken with Objective-C covariance?](https://forums.swift.org/t/casting-type-checking-in-swift-broken-with-objective-c-covariance/72137)

<div class="topic-metadata">

**Author:** [@Jon889](https://forums.swift.org/u/Jon889)\
**Replies:** 0\
**Last updated:** [May 29, 2024, 3:34pm UTC](https://forums.swift.org/t/casting-type-checking-in-swift-broken-with-objective-c-covariance/72137 "2024-05-29T15:34:32Z")

</div>

I know that swift doesn't have covariance for generics, so I wouldn't expect the following to work, but it does and prints true: let foo: SharedNetworkStateUIModel\<Parent\> = MRE.test() print(foo is SharedNetworkStateUIM…

---

## [Recommended Xcode settings for Release builds](https://forums.swift.org/t/recommended-xcode-settings-for-release-builds/28130)

<div class="topic-metadata">

**Author:** [@MrMage](https://forums.swift.org/u/MrMage)\
**Replies:** 1\
**Last updated:** [May 28, 2024, 7:05am UTC](https://forums.swift.org/t/recommended-xcode-settings-for-release-builds/28130 "2024-05-28T07:05:29Z")

</div>

Over time, I have accumulated the following build settings for my Release builds in Xcode 10 based on some of the older WWDC "Swift compilation/performance" sessions: SWIFT\_OPTIMIZATION\_LEVEL = -O SWIFT\_COMPILATION\_MODE…

---

## [Questions about the ClosureLifetimeFixup pass](https://forums.swift.org/t/questions-about-the-closurelifetimefixup-pass/70004)

<div class="topic-metadata">

**Author:** [@jkshtj](https://forums.swift.org/u/jkshtj)\
**Replies:** 15\
**Last updated:** [May 8, 2024, 11:58pm UTC](https://forums.swift.org/t/questions-about-the-closurelifetimefixup-pass/70004 "2024-05-08T23:58:09Z")

</div>

Hi, I am looking at an issue in Swift Autodiff where we're generating unoptimized code when the derivative of a function is called from a conditional control-flow context. Upon digging further I found out that the Clos…

---

## [How to make the swift compiler to remove unused code?](https://forums.swift.org/t/how-to-make-the-swift-compiler-to-remove-unused-code/71568)

<div class="topic-metadata">

**Author:** [@maxoog](https://forums.swift.org/u/maxoog)\
**Replies:** 0\
**Last updated:** [May 2, 2024, 7:21am UTC](https://forums.swift.org/t/how-to-make-the-swift-compiler-to-remove-unused-code/71568 "2024-05-02T07:21:51Z")

</div>

I set up a test project in Xcode and created two SPM targets. The first target depends on the second and uses a class from it, but there is also an unused public function in this class. I compiled the project and profile…

---

## [Why my '-cross-module-optimization' does not work?](https://forums.swift.org/t/why-my-cross-module-optimization-does-not-work/71555)

<div class="topic-metadata">

**Author:** [@maxoog](https://forums.swift.org/u/maxoog)\
**Replies:** 0\
**Last updated:** [May 1, 2024, 4:38pm UTC](https://forums.swift.org/t/why-my-cross-module-optimization-does-not-work/71555 "2024-05-01T16:38:44Z")

</div>

I set up a test project in Xcode to experiment with Cross-Module Optimization (CMO) in Swift. In my custom SPM package, I included a public function that isn't being used by other targets. To apply CMO, I updated the tar…

---

## [Closure specialization for reabstracted closures](https://forums.swift.org/t/closure-specialization-for-reabstracted-closures/71097)

<div class="topic-metadata">

**Author:** [@jkshtj](https://forums.swift.org/u/jkshtj)\
**Replies:** 1\
**Last updated:** [April 8, 2024, 8:36pm UTC](https://forums.swift.org/t/closure-specialization-for-reabstracted-closures/71097 "2024-04-08T20:36:37Z")

</div>

As it stands the closure-specialization optimization specializes a callsite against a closure that has undergone reabstractions (via reabstraction thunks) only if the final closure is passed in as a @noescape thick funct…

[Next page](https://forums.swift.org/tag/optimizations/239.md?match_all_tags=true&page=1&tags%5B%5D=optimizations)
