# PackageCompiler - reduce system image

**URL:** <https://discourse.julialang.org/t/packagecompiler-reduce-system-image/97952>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 26, 2023, 2:48pm UTC](https://discourse.julialang.org/t/packagecompiler-reduce-system-image/97952 "2023-04-26T14:48:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [April 26, 2023, 2:48pm UTC](https://discourse.julialang.org/t/packagecompiler-reduce-system-image/97952/1 "2023-04-26T14:48:09Z")

</div>

Hi,  
I was looking at the doc of PackageCompiler but couldn’t find the information I was looking for.  
Is there options to strip metadata, ir, documentation, some standard libraries…etc from the system image when building a system image?  
If yes, can someone provide an example?  
Thank you

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [April 26, 2023, 3:23pm UTC](https://discourse.julialang.org/t/packagecompiler-reduce-system-image/97952/2 "2023-04-26T15:23:15Z")

</div>

Strip metadata/ir: see

> [@Code obfuscation | Using the \`--strip-ir\` option in PackageCompiler.jl](https://discourse.julialang.org/t/code-obfuscation-using-the-strip-ir-option-in-packagecompiler-jl/91426):
>
> I would like to distribute my package while hiding the source code. I came across PackageCompiler.jl and julia’s --strip-ir option to help, but when I load a sysimage generated using that option, I get an error that some source code is not available. Here is an example on a simple package with detailed steps: I have a module SimplePkg: module SimplePkg export nodoc nodoc(x) = sin(sqrt(x)) """ Returns sin(sqrt(x)) """ withdoc(x) = nodoc(x) end # module and a script “scratch.jl” that uses t…

strip standard libraries: see PackageCompiler docs here:

> **[References · PackageCompiler](https://julialang.github.io/PackageCompiler.jl/dev/refs.html#PackageCompiler.create_sysimage)**
>
> Documentation for PackageCompiler.

(in particular:

> `filter_stdlibs::Bool`: If `true`, only include stdlibs that are in the project file. Defaults to `false`, only set to `true` if you know the potential pitfalls.

)

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [April 26, 2023, 3:32pm UTC](https://discourse.julialang.org/t/packagecompiler-reduce-system-image/97952/3 "2023-04-26T15:32:08Z")

</div>

Note, you need Julia 1.9 (which has release candidates, but should be out in hours, if not days). And you likely want to use --strip-metadata too, and possibly delete LLVM (which is largest), and maybe more dependencies.

I’m writing for small apps, more than maybe smaller sysimage. The sysimage doesn’t seem like as much of a deal any more with pkgimages. See also, if still as relevent:

> **[GitHub - petvana/AutoSysimages.jl: Automate user-specific system images for...](https://github.com/petvana/AutoSysimages.jl)**
>
> Automate user-specific system images for Julia. Contribute to petvana/AutoSysimages.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [April 26, 2023, 3:41pm UTC](https://discourse.julialang.org/t/packagecompiler-reduce-system-image/97952/4 "2023-04-26T15:41:28Z")

</div>

Thanks to both. Where do I pass --strip-metadata? When I launch julia? Can pass --strip-ir as well? How do I delete LLVM?  
Thanks again.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [April 26, 2023, 3:43pm UTC](https://discourse.julialang.org/t/packagecompiler-reduce-system-image/97952/5 "2023-04-26T15:43:53Z")

</div>

I guess:

```julia
using PackageCompiler
create_sysimage(:SimplePkg, sysimage_path="SimplePkg_StripIR.so", precompile_execution_file="scratch.jl", sysimage_build_args=`--strip-ir --strip-metadata`)

```

I saw this in the linked thread, only added `--strip-metadata`. And it (both) off the screen to the right, so easy to miss.

You can see LLVM in the generated app, an .so file, or .dll (on Windows) etc. Likely lower case llvm.so. If you’re just making a sysimage, then this doesn’t apply; do not delete your main Julia LLVM…! 🙂

---

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [April 27, 2023, 8:29am UTC](https://discourse.julialang.org/t/packagecompiler-reduce-system-image/97952/6 "2023-04-27T08:29:46Z")

</div>

After building some system images (which takes a lot of time), here is what works for me :

- sysimage\_build\_args = `--strip-metadata` this produce the smallest system image for me (225MB)
- sysimage\_build\_args = `--compile=all --strip-metadata --strip-ir` produce 297MB, --compile=all is important otherwise it does not work.
- sysimage\_build\_args = `--compile=all --strip-metadata --strip-ir` + filter\_stdlibs=true + incremental=false produce 266MB.

Thank you for your help on this.
