And one of my other projects also went from initially using ~3MB and then creeping up to ~30MB to initially using ~70MB
Memory usage measured with docker stats when running the image built with the included Dockerfile. Haven't tested my other projects or Swift 6.2.4 yet.
When building with the regular SDK, the template project uses 884.7kB memory with Swift 6.2.3 and 909.3kBkB with Swift 6.3.0, which is still an increase but not as bad as with the Static Linux SDK. (Linux Mint 22.3, memory usage measured with System Monitor)
The most likely cause of the change here is the switch to using mimalloc; my guess is that the extra memory usage might not be quite what it seems (it's probably just the allocator grabbing a large chunk of memory to use as a pool).
Setting MIMALLOC_ALLOW_LARGE_OS_PAGES=0 seems to return memory usage to normal levels. The template project is using 331.8kB.
The other project started at 4.5-4.7MB and slowly increasing (periodic url requests are made to refresh data) and then increasing faster when the page is opened (and then force refreshed) in the browser and it needs to generate HTML. And then it seems to stabilize at 10.4-10.5MB. (Haven't tested long enough to see if the "and then creeping up to ~30MB" is still true)
If I also set MIMALLOC_PURGE_DECOMMITS=0 in the other project, nothing seems to change.
Setting MIMALLOC_ALLOW_LARGE_OS_PAGES=1 in the other project seems to work as the default 2. (~70MB baseline memory usage)
Setting MIMALLOC_ARENA_EAGER_COMMIT=0 instead of disallowing large os pages seem to have similar effect. The template project is at 319.5kB, the other project is still at 4.5-4.7MB start and 10.4-10.5MB top.
Is there a way to keep both static SDKs installed? Switching to Swift 6.3.0 and installing the static SDK for that too wanted to build with the static SDK for 6.2.3 when using the swift build --configuration release --swift-sdk x86_64-swift-linux-musl command.
edit: These numbers are from System Monitor. Running inside docker and using docker stats probably gives slightly different numbers.
edit2: In docker with MIMALLOC_ARENA_EAGER_COMMIT=0 it seems to top out at 25-27MB while continuously force refreshing the page to rerender the HTML.
You might be able to do this by specifying the SDK using the name from swift sdk list and then passing x86_64-swift-linux-musl as the --triple argument instead.
No, this is currently broken, one of the SwiftPM bugs I'm fixing. You must currently uninstall the non-matching static linux SDK for the compiler version you are using.
I'm trying to build the sdk without mimalloc, currently failing at Patching Musl for locale support... but if I go there on the host machine and try to apply the patch then it succeeds
Yes, that's likely the cause of the problem. The build script tends to get tinkered with (it isn't what the CI system uses, it's just for local use) and getting everything just right can be a pain.
That tends to happen if your Docker container doesn't have enough memory (it's the OOM killer). Increasing the setting in the build script should resolve it (I have mine set to 20G); the default, 10G, used to be sufficient but apparently isn't now.
In an ideal world we would in fact just build the runtime and don't need to even build the Swift compiler. The issue is that the Swift build process isn't really set up well for that. We probably could start using the new CMake-based runtime build in the Runtimes directory instead, which should mean we no longer end up unnecessarily building the compilers.
I have this use of the --swift-sdk <SDK> --triple <triple> flag with SDK bundles fixed in the latest Apr. 22 trunk snapshot: try it with Android or one of the compatible Apr. 22 SDK snapshots, as unfortunately the trunk static linux SDK CI is broken right now.
Yep, build successfully finished even without this part.
Building with this modified SDK seems to return memory usage levels to 0.0.1. (I still need to setup a new CI VM with more RAM, so the build is pushed to docker hub.)
Download or docker.io/cyberbeni/swift-builder:6.3.1-musl-allocator docker image if anyone wants to try without building it themselves for a couple hours.