Split the Swift package into one library per service
An app that imported the Swift SDK linked all 58 services, whatever it called. A one-call iOS app (Release, generic iOS, Xcode 27.2) was 4,380 KB, of which 4,120 KB was the Basecamp module.
Root cause, measured from the linker map: Swift marks every public symbol no_dead_strip, and the type and protocol-conformance records keep every model's Codable witnesses and every service's vtable alive. Dead stripping removed 12.5 KB of the module. Models were 2.95 MB of it (1.7 MB Codable), services 0.55 MB. -internalize-at-link only reached 3.88 MB, and it and -conditional-runtime-records both need unsafeFlags, which SwiftPM refuses for version-pinned dependencies. Inside a module nothing is strippable, so the module boundary is the lever.
What changes
- Targets.
BasecampCoreholds the client, transport, errors, pagination,BaseService, and every model that two or more services (or none) reach. Each service gets aBasecamp<Service>target and product: the service, its options, itsaccount.<service>accessor, and the models only it reaches.BasecampMentionsandBasecampRecordingSummarieshold the composites that call several services.Basecampis the umbrella and re-exports all of them, soimport Basecampcode is unchanged apart from the renames. - Placement is generated. Files stay under
swift/Sources/Basecamp. The generator places every file in exactly one target (swift/Sources/BasecampGenerator/TargetPlan.swift) and writes the table into a marked block in bothPackage.swiftfiles. The manifests compute each target's excludes, so SwiftPM reports no unhandled files.check-swift-service-drift.shnow regenerates the manifest tables too. - Renames (Swift only).
CalendarbecomesBasecampCalendarandNotificationbecomesBasecampNotification. Both were ambiguous with Foundation's types in any file importing both. The old names are@available(*, unavailable, renamed:)aliases in the umbrella. A deprecated alias would still take part in lookup and keep the ambiguity. The unavailable alias breaks only code that meant Basecamp's type, and gives a fix-it.BasecampPublicAPIConsumer/NameCollisions.swiftcompiles bare FoundationCalendar/NotificationandBasecamp.Pingagainst app-declared types. BasecampDynamicis the umbrella as a dynamic framework, for apps whose extensions also use the SDK.- Size budget.
make swift-size-check, run in the Swift CI job, buildsswift/SizeBudget's one-call app for iOS. It fails when the app grows past its budget inswift/SizeBudget/budget.json. Budgets are kept per Xcode major, because the same sources link to different sizes under each toolchain: 734,624 bytes on Xcode 27.2 and 1,524,640 on CI's Xcode 16.4. Each budget is about 10% over the measurement. An Xcode major with no budget recorded fails and prints the measurement to record. A change that moves a service's models into core shows up as growth. - Hand-written code across targets.
BasecampClient.campfireIndexmoves out of core into a per-clientClientStorage, with an extension inCampfireIndex.swift.internalbecomespackagewhere another target needs a declaration:ZeroPerson,decodePeople*,BaseService.decoding/pathSegment,Metadata,queryString,goWhitespace. Tests import@testable BasecampCoreplus the composite modules they exercise. - Scripts.
sync-doc-constants.rbandcheck-service-inventory-parityread Swift's accessors fromGenerated/Accessors/(one file per service) instead ofAccountClient+Services.swift. Their self-tests are updated.
Measurements
Same harness before and after: Release, generic iOS, Xcode 27.2, linked executable size.
| App | Before | After |
|---|---|---|
| empty, no SDK | 67 KB | 67 KB |
one call, import BasecampBookmarks | 4,380 KB | 735 KB |
directory + to-dos + bookmarks (BasecampProjects, BasecampTodos, BasecampBookmarks) | 4,380 KB | 861 KB |
| one call via the umbrella / every service | 4,380 KB | 3,533 KB |
one call via BasecampDynamic | n/a | 69 KB executable + 3,912 KB framework |
The one-call app, import BasecampBookmarks, on both toolchains:
| Toolchain | Before (one Basecamp module) | After | Budget |
|---|---|---|---|
| Xcode 27.2 (measured here) | 4,380 KB | 735 KB (734,624 B), 17% of before | 820,000 B |
Xcode 16.4 (CI's macos-15) | not measured: no Xcode 16 here, and CI only builds the split package | 1,525 KB (1,524,640 B), 35% of the 27.2 baseline | 1,680,000 B |
Xcode 16.4 links the same sources to about twice the size 27.2 does, so its row is not a like-for-like before/after. The comparison with the 4,380 KB baseline holds on 27.2.
Lane M's 6.18 MB figure was measured against a merge of several in-flight branches, so it isn't comparable to the main-based numbers above.
Not done here
- Placing shared models in an owner target instead of core (option B) would take roughly another 250 KB off the smallest apps. Core is 650 KB of the 735, 347 KB of it models. Deferred.
- Composite dependencies are over-approximated. They come from a token scan of class names and
.accessoruses, so they may include a service a composite doesn't call. That costs size only for apps that usesummarize. - One stale prose mention.
spec/doc-constants.jsonstill namesAccountClient+Services.swiftin its rationale. It is left alone because aspec/change triggers a release. - CI's toolchain is older than the one I measured on. The Swift job runs Xcode 16.4 on
macos-15; I probed and measured on Xcode 27.2. On 16.4 the build and tests pass, which covers the shared-path targets and the unavailable-alias lookup inNameCollisions.swift. Sizes for both toolchains are in the table above.
Outside review (dual-model, on a42ac9a9)
Fixed, each with a test that failed first where one could:
- The placement scan stripped comments before strings. So
"https://…"hid the rest of its line, and a string interpolation hid the model it named. It is now one left-to-right pass that keeps code inside interpolations (codeOnlyinTargetPlan.swift);TargetPlanTestshas three new cases. The committed placement did not change. - Composite dependency discovery saw
.accessortokens inside strings and block comments. It now uses the same pass. - Two services claiming one hand-written file trapped. That case now throws. A composite listing
BasecampCoreexplicitly no longer duplicates the dependency. BasecampMentionsandBasecampRecordingSummariesdid not re-exportBasecampCoreor the service they extend, so a file importing only one of them could not nameBasecampClientorPerson. They now re-export both. The new non-test targetBasecampCompositeConsumercompiles against each module alone.- A non-integer budget made the size gate's
-gterror out, and the gate passed. Every budget must now be a positive integer. - The core-closure test passed even with the closure pass removed. It now pins a model to core through a core source, so only the closure pass moves the model it names.
- A new test covers the Campfire index across
forAccountwrappers (shared) and across clients (separate). - Smaller fixes:
- the MIGRATING and
Umbrella.swifttext on when the fix-it appears; - a README note not to mix
BasecampDynamicwith static products; swift/SizeBudgetbuild output added to.gitignore;Dir.childreninstead ofDir.globinsync-doc-constants.rb;swiftTypeNameinServiceEmitter's last fallback. That fallback is unreachable with today's spec, so it has no test.
- the MIGRATING and
Declined:
- A generator run with only
--outputpointing at a scratch directory fails. That refusal is intended: placing files needs the hand-written sources. The error says to pass--sources, and the Makefile and the drift check both pass it. - Multi-file fixtures for the accessor self-tests of
sync-doc-constants.rband the parity check. Both gates run on every PR against the real 58-fileGenerated/Accessors/, which already exercises the multi-file case. - Composite discovery ignores
*Optionsand*Resulttypes. A missed dependency failsswift build, so the gap cannot ship silently.
Outside review, second pass (on b950d4d6)
Fixed, each with a test that failed first:
- The scanner misread a one-line raw string like
#"""#as a multi-line string, which hid the rest of the file."""now opens a multi-line string only when nothing but whitespace follows it on its line. - A generator run with only
--outputset took the parent of--outputas the source root, so a scratch output under/tmpwalked all of/tmp.--sourcesnow defaults toSources/Basecamp, matching--output's own default. The walk also skips an output directory that sits inside the root. This answers the first pass's--output-only finding too: a scratch run fromswift/now succeeds and leaves both manifests byte-identical. - The composite consumer imported
BasecampMentionsonly throughBasecampRecordingSummaries. It is now two targets.BasecampMentionsConsumerdepends only onBasecampMentionsand also callscreateWithMentions.BasecampRecordingSummariesConsumerdepends only onBasecampRecordingSummaries.PublicInitCoverageTestsholds three things for both: plain imports of the one module, a plain.target, and that single dependency.
Declined:
- "Recording summaries depend on
BasecampMentionsonly forgoWhitespace." Not so:summarizecallsMentions.personIds(in:)to fillmentionedPersonIds(RecordingsServiceExtensions.swift, the chat-line and projection paths). MovinggoWhitespaceinto core would not remove the dependency. Putting the mention parser in its own target would let summaries dropBasecampPeopleand the comment composites; it already depends onBasecampComments. That is a small size change forsummarize-only apps, so I left it for later. - The size gate passes if
OneOperationstops calling the SDK. That takes a deliberate edit to the harness, and the edit is reviewed like any other diff. The gate guards against placement drift, not against harness edits. - No check catches deleting the root
BasecampDynamicproduct. That deletion is a visible diff in a hand-written manifest. - Some helpers widened to
packagehave no caller outside core.packageis invisible outside this package, so nothing public changes. Narrowing them is churn for no consumer. - Composite discovery matches any
.accessortoken, whatever its receiver. This over-approximation is already documented above. It can only add a dependency, which costs size forsummarizeusers and never breaks the build.
Outside review, third pass (on 9eab459b)
No high-severity findings. Fixed in the last push, each with a test that failed first:
- Two schemas emitting one Swift name are now refused. If a
BasecampCalendarschema were added besideCalendar, the generator used to keep only the later model and write one file, silently. It now stops before deleting or writing anything and names both schemas.ModelRegistrycompares names, and compares paths case-insensitively. This retracts my second-pass decline, which wrongly assumedswift buildwould catch it. - SPEC §18 rule 5 and Appendix F's Swift row now name the Swift composite targets. The text said "same-module extension"; it now names the targets
TargetPlan.swiftdeclares (BasecampMentions,BasecampRecordingSummaries).TargetPlanTestschecks that rule 5 names every declared composite. handWrittenSourcesnow resolves symlinks before comparing the root and output paths, so/tmpvs/private/tmpno longer matters.- The composite-consumer import guard now sees access-modified and attributed imports, such as
internal import Xand@preconcurrency public import X. - The size check's judging half is
scripts/swift-size-verdict.rb. It reads the size with Ruby'sFile.sizerather thanstat -fand refuses an empty binary.scripts/test-swift-size-verdict.rbtests it with no Xcode needed: a float or string budget, a missing major, an empty binary, over budget, and a GNUstatfirst onPATH.make swift-size-checkruns that self-test first.
Declined:
- The size gate measures only the executable, so a dynamically linked
BasecampBookmarkswould shrink it. Making that product dynamic is a visible edit to a hand-written manifest. - The planner does not scan generated accessor bodies or generated core files. Accessors name only their own service class, and
MetadataandQueryStringname no models. A core file naming a service's model failsswift build. - Products removed from the root manifest, and multi-file fixtures for the accessor self-tests. Both re-raise declines from the earlier passes, with nothing new.
The full dual review was not re-run after this push. Its findings fell each pass, and this pass had no high-severity ones. Anything that surfaces later becomes a follow-up, not another push on this PR.
#1151 (service protocols) is compatible: each protocol and its conformance land in the service's own target. The budget gets re-measured once #1151 lands.