Our CI stack is running in a Docker container which is restricted on memory usage, it was noticed that with Swift 5.8 toolchain sometimes runs out of memory in the container with 7GB memory limit.
Investigating a clean build comparison between the two toolchains, it is visible that peak memory usage with 5.7 is under 3.7GB, while with 5.8 this reaches 7GB. The memory consumption occurs when a large number of swift-frontend processes are created and are alive simultaneously (100-200+). It appears that the individual swift-frontend memory usage has risen in 5.8.
Steps to reproduce
Monitor peak memory usage in a container for the same project and a clean build.
Start a container with 5.7 and 5.8:
docker run -v $HOME:/build --name swift5.7 -ti swift:5.7-focal /bin/bash
docker run -v $HOME:/build --name swift5.7 -ti swiftlang/swift:nightly-5.8-jammy /bin/bash
Set up process monitoring:
while true; do echo "$(date): $(docker stats --no-stream --format "{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" swift5.7)" ; sleep 1; done >> docker_stats_5.7
while true; do echo "$(date): $(docker stats --no-stream --format "{{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" swift5.8)" ; sleep 1; done >> docker_stats_5.8
In each of them also can setup processes monitoring every second:
docker exec -ti swift5.7 top -o RES -b 1 > top_batch_5.7
docker exec -ti swift5.8 top -o RES -b 1 > top_batch_5.8
With this setup, it is visible that the peak is at 16:06:30-16:06:43
Mon Feb 27 16:06:27 UTC 2023: swift5.8 104.08% 46.89MiB / 125.7GiB
Mon Feb 27 16:06:30 UTC 2023: swift5.8 99.10% 80.21MiB / 125.7GiB
Mon Feb 27 16:06:33 UTC 2023: swift5.8 2342.30% 4.486GiB / 125.7GiB
Mon Feb 27 16:06:36 UTC 2023: swift5.8 2201.98% 7.044GiB / 125.7GiB <---- 7GB
Mon Feb 27 16:06:40 UTC 2023: swift5.8 2250.05% 4.862GiB / 125.7GiB
Mon Feb 27 16:06:43 UTC 2023: swift5.8 2238.20% 1.426GiB / 125.7GiB
Mon Feb 27 16:06:46 UTC 2023: swift5.8 408.49% 383.6MiB / 125.7GiB
Mon Feb 27 16:06:49 UTC 2023: swift5.8 1587.51% 371.6MiB / 125.7GiB
Mon Feb 27 16:06:52 UTC 2023: swift5.8 2112.01% 1.066GiB / 125.7GiB
Mon Feb 27 16:06:55 UTC 2023: swift5.8 545.89% 437.8MiB / 125.7GiB
And top analysis shows swift-frontend processes get created, each using up to 200MB of memory:
Our CI stack is running in a Docker container which is restricted on memory usage, it was noticed that with Swift 5.8 toolchain sometimes runs out of memory in the container with 7GB memory limit.
Investigating a clean build comparison between the two toolchains, it is visible that peak memory usage with 5.7 is under 3.7GB, while with 5.8 this reaches 7GB. The memory consumption occurs when a large number of
swift-frontend
processes are created and are alive simultaneously (100-200+). It appears that the individualswift-frontend
memory usage has risen in 5.8.Steps to reproduce Monitor peak memory usage in a container for the same project and a clean build.
Start a container with 5.7 and 5.8:
Set up process monitoring:
In each of them also can setup processes monitoring every second:
With this setup, it is visible that the peak is at
16:06:30-16:06:43
And top analysis shows
swift-frontend
processes get created, each using up to 200MB of memory:With 5.7, the peak memory for me doesn't go over at more than 3.7GB and here only managed 2GB peak:
and from top each one is also using less memory:
Expected behavior
Restricted memory usage growth during the peak.
Should the rate at which swift-frontend processes are spawned be controlled?
Environment
And 5.7: