# AsyncAlgorithms bloat persists even after stripping and link-time-optimizations

**URL:** <https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479>\
**Category:** Swift Async Algorithms\
**Created:** [March 21, 2026, 6:14pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479 "2026-03-21T18:14:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [March 21, 2026, 6:14pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/1 "2026-03-21T18:14:50Z")

</div>

this isn’t a [new problem](https://forums.swift.org/t/how-to-merge-nioasyncchannelinboundstream-into-another-stream-without-losing-backpressure/70301/3), but i am surprised it persists to this day, and remains resistant to all of the remedies that were predicted to mitigate it.

i did an experiment on Swift 6.2.4 creating a [minimal server application](https://github.com/rarestype/servit/tree/master/Examples) that depends on SwiftNIO and AsyncAlgorithms, and compared the size of the compiled binary when using AsyncAlgorithms, and when literally copy-pasting the source files of `AsyncChannel` into a vendored copy of the module within the project.

**Ubuntu 24.04**

| stage | size (bytes, `AsyncAlgorithms`) | size (bytes, vendored copy) |
| --- | --- | --- |
| original | 47,813,400 | 44,327,624 |
| [after `strip`](https://github.com/rarestype/servit/actions/runs/23370401642/job/67992765626) | 11,327,736 | 9,975,752 |
| [with LTO](https://github.com/rarestype/servit/actions/runs/23382863537/job/68025025629) | 10,274,616 | 8,985,856 |

**macOS 26**

| stage | size (bytes, `AsyncAlgorithms`) | size (bytes, vendored copy) |
| --- | --- | --- |
| original | 18,194,792 | 16,003,880 |
| [after `strip`](https://github.com/rarestype/servit/actions/runs/23370401642/job/67992765625) | 8,193,496 | 7,024,776 |
| [with LTO](https://github.com/rarestype/servit/actions/runs/23382863537/job/68025025656) | 8,348,232 | 7,248,088 |

aside from the strange situation where `--experimental-lto-mode full` actually makes the binary larger on macOS, it is apparent that vendoring the source files of `AsyncChannel` is still the clear winner by a considerable margin.

when i first encountered this problem years ago, i was advised that dead code/symbols stripping and the (at the time, upcoming) `swift build --experimental-lto-mode full` feature would resolve the problem by design. but that has not really panned out.

---

<div class="post-metadata">

**Author:** ![RandomHashTags](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/randomhashtags/32/24259_2.png) [@RandomHashTags](https://forums.swift.org/u/RandomHashTags)\
**Post date:** [March 23, 2026, 6:21pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/2 "2026-03-23T18:21:03Z")

</div>

The only solution I've found to reduce binary size of projects is to use package traits for every offending piece of code. That is the main reason why I wrote my own networking library without SwiftNIO and Foundation, and the minimal server I wrote using it came under 1 MB (without explicit flags or special linking; could shave it down to \< 500 KiB if you disabled some package traits, suitable for embedded).

With Swift 6.3 around the corner and 6.1 becoming the last 'supported' minor release, I really hope more packages utilize package traits. Some of the popular libraries already require 6.1 or later yet they don't use them... ☹

---

<div class="post-metadata">

**Author:** ![Jon\_Shier](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jon_shier/32/921_2.png) [@Jon\_Shier](https://forums.swift.org/u/Jon_Shier)\
**Post date:** [March 23, 2026, 11:40pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/3 "2026-03-23T23:40:11Z")

</div>

With Xcode 26.4 finally adding support for them (though I don't know how good it is), they should be more viable in the near future. Biggest issue right now is that using traits in packages randomly breaks stuff in Xcode, so I've generally avoided them in my packages, and packages that use them.

---

<div class="post-metadata">

**Author:** ![Finagolfin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finagolfin/32/34388_2.png) [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Post date:** [March 26, 2026, 6:12am UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/4 "2026-03-26T06:12:29Z")

</div>

Note that this code bloat is something [the Android workgroup has been discussing in recent months](https://forums.swift.org/t/prospective-vision-networking/85235/8), and some of us want to look into more. @lukasa and [@vedantk or @akyrtzi](https://github.com/swiftlang/swift/pull/22839), are there any subject matter experts for this in the Swift project who we should be discussing our findings with?

It seems like this is a high-impact effort that would help _all_ Swift platforms, such as @compnerd with Windows too if employing the right Windows-specific tools there, would be good to set up some knowledge-sharing and collaboration on this important issue @taylorswift brings up.

---

<div class="post-metadata">

**Author:** ![lukasa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lukasa/32/1232_2.png) [@lukasa](https://forums.swift.org/u/lukasa)\
**Post date:** [March 26, 2026, 1:20pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/5 "2026-03-26T13:20:25Z")

</div>

I’m honestly not sure who the best person to talk to is. I’d suggest we start with @tbkka and see if he has a suitable suggestion.

---

<div class="post-metadata">

**Author:** ![FranzBusch](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/franzbusch/32/19447_2.png) [@FranzBusch](https://forums.swift.org/u/FranzBusch)\
**Post date:** [March 26, 2026, 2:01pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/6 "2026-03-26T14:01:35Z")

</div>

I think this is a good problem to tackle. In my opinion, we should start off with creating tooling similar to [bloaty](https://github.com/google/bloaty) that helps us analyze binaries and understand where the binary size is coming from. Potentially also writing a documentation article about this.

---

<div class="post-metadata">

**Author:** ![Finagolfin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finagolfin/32/34388_2.png) [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Post date:** [March 27, 2026, 5:43pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/7 "2026-03-27T17:43:37Z")

</div>

It looks like [people are already using it on Swift](https://asifmohd.github.io/ios/2022/02/03/bloaty-ios-introduction.html), 😀 @taylorswift, want to try it on your example and see what you find?

---

<div class="post-metadata">

**Author:** ![rauhul](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rauhul/32/35207_2.png) [@rauhul](https://forums.swift.org/u/rauhul)\
**Post date:** [March 27, 2026, 7:38pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/8 "2026-03-27T19:38:13Z")

</div>

> [@taylorswift](#):
>
> swift build --experimental-lto-mode full

FWIW I added this to support a very early variant of embedded swift. It needs to be combined with --internalize-at-link and a couple other flags to really have an effect. Desktop swift today isn't able to dead strip as effectively as embedded due to things like reflection metadata. I'll avoid speaking more concretely as I don't understand the full details.

cc @Douglas_Gregor @Slava_Pestov might be able to explain what type metadata keeps "dead" code around. (or if thats even correct).

* * *

edit: 3-4 year old flag list:

```swift
-Ospeed
-Xfrontend -experimental-hermetic-seal-at-link
-whole-module-optimization
-Xfrontend -disable-reflection-metadata

```

today I _think_ you might use: `-enable-cmo-everything`

---

<div class="post-metadata">

**Author:** ![hassila](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hassila/32/22647_2.png) [@hassila](https://forums.swift.org/u/hassila)\
**Post date:** [March 27, 2026, 7:55pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/9 "2026-03-27T19:55:53Z")

</div>

@taylorswift check internal sc-128 - we did try this and intended to have it in CI.

Basically bloaty 1.1 or later worked on macOS (but not on Linux) at that point in time (2023?).

It was possible to get output such as:

```swift

    FILE SIZE VM SIZE    
 -------------- -------------- 
  10.2% 1.93Mi 10.0% 1.93Mi [__LINKEDIT]
   5.8% 1.10Mi 5.7% 1.10Mi /Users/hassila/GitHub/ordo/LocalPackages/Cache/Sources/Cache/CacheStorable.swift
   4.0% 777Ki 3.9% 777Ki /Users/hassila/GitHub/ordo/Modules/Augmentation/Sources/Augmentation/Augmentation+Module.swift
   3.5% 686Ki 3.5% 686Ki /Users/hassila/Library/Developer/Xcode/DerivedData/Ordo-gmejvaknewiunvewtbtnixiriytp/SourcePackages/checkouts/swift-lmdb/Sources/CLMDB/mdb.c
   2.2% 432Ki 2.2% 432Ki [__TEXT,__ eh_frame]
   2.2% 431Ki 2.2% 431Ki [__TEXT,__ cstring]
   2.0% 382Ki 1.9% 382Ki [__TEXT,__ text]
   1.8% 349Ki 1.8% 349Ki /Users/hassila/Library/Developer/Xcode/DerivedData/Ordo-gmejvaknewiunvewtbtnixiriytp/SourcePackages/checkouts/swift-protobuf/Sources/SwiftProtobuf/descriptor.pb.swift
   0.3% 53.3Ki 1.7% 335Ki /Users/hassila/Library/Developer/Xcode/DerivedData/Ordo-gmejvaknewiunvewtbtnixiriytp/SourcePackages/checkouts/swift-kafka-client/Sources/Crdkafka/librdkafka/src/rdkafka_sticky_assignor.c
   1.2% 239Ki 1.2% 239Ki [__TEXT,__ unwind_info]
   1.0% 199Ki 1.0% 199Ki [__TEXT,__ swift5_typeref]
   1.0% 197Ki 1.0% 197Ki /Users/hassila/GitHub/ordo/LocalPackages/Cache/Sources/Cache/Cache.swift
   1.0% 191Ki 1.0% 191Ki /Users/hassila/Library/Developer/Xcode/DerivedData/Ordo-gmejvaknewiunvewtbtnixiriytp/SourcePackages/checkouts/swift-kafka-client/Sources/Crdkafka/librdkafka/src/rdkafka_topic.c
   1.0% 191Ki 1.0% 191Ki /Users/hassila/Library/Developer/Xcode/DerivedData/Ordo-gmejvaknewiunvewtbtnixiriytp/SourcePackages/checkouts/swift-kafka-client/Sources/Crdkafka/librdkafka/src/snappy.c

```

```swift

cli-developer-utilities git:(main) ✗ bloaty --demangle=full .build/debug/ordo-cache-tool 
    FILE SIZE VM SIZE    
 -------------- -------------- 
  38.0% 7.80Mi 37.6% 7.80Mi String Table
  34.6% 7.10Mi 34.3% 7.10Mi __TEXT,__ text
  17.3% 3.54Mi 17.1% 3.54Mi Symbol Table
   3.6% 755Ki 3.6% 769Ki [__LINKEDIT]
   0.0% 0 1.1% 227Ki __DATA,__ bss
   1.0% 212Ki 1.0% 212Ki __TEXT,__ eh_frame
   1.0% 202Ki 1.0% 202Ki __TEXT,__ const
   0.8% 175Ki 0.8% 175Ki __DATA_CONST,__ const
   0.8% 162Ki 0.8% 162Ki Code Signature
   0.5% 102Ki 0.5% 102Ki __TEXT,__ unwind_info
   0.4% 91.0Ki 0.4% 87.4Ki [26 Others]
   0.4% 81.1Ki 0.4% 81.1Ki __TEXT,__ cstring
   0.3% 64.2Ki 0.3% 64.2Ki __DATA,__ data
   0.3% 52.6Ki 0.2% 52.6Ki __TEXT,__ swift5_fieldmd
   0.2% 48.6Ki 0.2% 48.6Ki Function Start Addresses
   0.2% 38.7Ki 0.2% 38.7Ki __TEXT,__ swift5_typeref
   0.2% 36.9Ki 0.2% 36.9Ki __DATA,__ objc_const
   0.2% 32.6Ki 0.2% 32.6Ki __TEXT,__ swift5_reflstr
   0.1% 18.4Ki 0.1% 18.4Ki __TEXT,text_env
   0.1% 16.3Ki 0.1% 16.3Ki __DATA_CONST,__ got
   0.1% 15.5Ki 0.1% 15.5Ki [__DATA_CONST]
 100.0% 20.5Mi 100.0% 20.7Mi TOTAL

```

Overall this would be good - but given that bloaty works (good enough?!) - perhaps worth checking status and upstreaming any missing pieces? Not sure it helps for android/windows though…

---

<div class="post-metadata">

**Author:** ![madsodgaard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/madsodgaard/32/43318_2.png) [@madsodgaard](https://forums.swift.org/u/madsodgaard)\
**Post date:** [March 28, 2026, 12:01pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/10 "2026-03-28T12:01:55Z")

</div>

The best results (the smallest binary) I could get for an dynamic Android library, was with:

```swift
--Xswiftc -Osize
-Xlinker --version-script=my-exported-symbols.map 
--experimental-lto-mode=full
-Xfrontend -internalize-at-link

```

Does that look right? Am I missing anything?

---

<div class="post-metadata">

**Author:** ![rjmansfield](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rjmansfield/32/36826_2.png) [@rjmansfield](https://forums.swift.org/u/rjmansfield)\
**Post date:** [March 31, 2026, 2:07pm UTC](https://forums.swift.org/t/asyncalgorithms-bloat-persists-even-after-stripping-and-link-time-optimizations/85479/11 "2026-03-31T14:07:43Z")

</div>

Bloaty 1.1 is ~6years old so I recommend using the latest bloaty from source. A number of fixes for bloaty to work better with Swift binaries have landed recently, e.g. improved dwarf5 support, improved handling of dsyms, support for demangling Swift symbols. There’s a few pending pull requests as well that also improve bloaty support on macOS, such as support for archives, and fixes for vm addressing in universal binaries.
