Skip to content

The performance of static Linux binary is bad #6298

@ainame

Description

@ainame

New Issue Checklist

Bug Description

0.61.0 introduced experimental fully static Linux binary with Static Linux SDK. I fixed its crash issue #6287 and 0.62.1 was released. But it looks like the performance is significantly slow #6291 (comment)

This is not formal benchmark but static Linux binary is about 3 time slower than just normal release build on my end (Ubuntu Desktop 24.04 on VMware running on M4 Max with 8 cores/16GB memory allocated).

# v0.62.1 binary downloaded from GitHub Release
ainame@ainame-vm:~/repos/SwiftLint$ time ./swiftlint-static --no-cache 2&>1 /dev/null 

real	0m4.300s
user	0m13.376s
sys	0m10.517s

# Normal release build at main branch 32cf983
# swift build --product swiftlint -c release -Xswiftc -DSWIFTLINT_DISABLE_SOURCEKIT
ainame@ainame-vm:~/repos/SwiftLint$ time .build/aarch64-unknown-linux-gnu/release/swiftlint --no-cache  2&>1 > /dev/null

real	0m1.353s
user	0m6.682s
sys	0m0.127s

I suppose this is kind of expected that musl's allocator seems to be known as slow and found many Rust devs complaint about it.

https://nickb.dev/blog/default-musl-allocator-considered-harmful-to-performance/
nextstrain/nextclade#1338

In fact, when I just gave https://github.com/microsoft/mimalloc a try, it is as performant as normal release build. That said, it's better to get some benchmark/profile before introducing something new.

sudo apt-get install -y musl-tools cmake
git clone https://github.com/microsoft/mimalloc.git
cd mimalloc/
CC=musl-gcc CFLAGS="-O3" cmake -B build -DMI_BUILD_STATIC=ON -DMI_BUILD_SHARED=OFF
cmake --build build -j
cp build/libmimalloc.a ../SwiftLint/
ainame@ainame-vm:~/repos/SwiftLint$ swift build --product swiftlint \
    -c release \
    -Xswiftc -DSWIFTLINT_DISABLE_SOURCEKIT \
    --swift-sdk x86_64-swift-linux-musl  \
    -Xlinker -z -Xlinker stack-size=0x80000 \
    -Xlinker ~/repos/SwiftLint/libmimalloc.a
ainame@ainame-vm:~/repos/SwiftLint$ time .build/aarch64-swift-linux-musl/release/swiftlint --no-cache 2&>1 > /dev/null 

real	0m1.462s
user	0m7.844s
sys	0m0.123s

Environment

  • SwiftLint version 0.62.1
  • Xcode version N/A
  • Configuration file: N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIdeas for improvements of existing features and rules.integrationIssues related to integration of SwiftLint into toolchains.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions