What is needed to integrate jemalloc into a Swift application?

for a long time, i have been using export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libjemalloc.so.2 to add jemalloc to Swift applications, which i understand is sufficient for the default, dynamically-linked standard library build configuration.

according to the jemalloc wiki, this doesn’t necessarily work “if [the] application does not statically link a malloc implementation”. so i want to understand what this means in the context of --static-swift-stdlib.

  1. if i build with --static-swift-stdlib, but still dynamically link Glibc, will export LD_PRELOAD still work?

  2. if i build with --static-swift-stdlib, and also statically link Musl, will export LD_PRELOAD still work?

We've solved question 1 in Vapor, you can pass a linker flag to the compiler

does that mean export LD_PRELOAD is not doing anything in that scenario?

Correct

1 Like