# Creating a lIbrary with PackageCompiler takes ages

**URL:** <https://discourse.julialang.org/t/creating-a-library-with-packagecompiler-takes-ages/118927>\
**Category:** New to Julia\
**Created:** [September 2, 2024, 5:56am UTC](https://discourse.julialang.org/t/creating-a-library-with-packagecompiler-takes-ages/118927 "2024-09-02T05:56:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theo-L](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theo-l/32/211742_2.png) [@Theo-L](https://discourse.julialang.org/u/Theo-L)\
**Post date:** [September 2, 2024, 5:56am UTC](https://discourse.julialang.org/t/creating-a-library-with-packagecompiler-takes-ages/118927/1 "2024-09-02T05:56:04Z")

</div>

I’m trying to creating a library for my module using PackageCompiler but it takes forever. At this point the script is already running for 9 hours. Any ideas how I can speed this up?

```julia
create_library(
    package_or_project,
    dest_dir;
    lib_name = "lib.so", # Custom name for the compiled library
    incremental = false, # Create a fresh sysimage from scratch for maximum reliability
    filter_stdlibs = false, # Only include standard libraries that are in the project file
    force = false, # Force re-creation of the library if it already exists
    include_lazy_artifacts = false, # Avoid lazy artifacts for simplicity and better performance
    include_transitive_dependencies = true, # Include all dependencies to ensure full functionality
    include_preferences = true, # Include project preferences
    sysimage_build_args = `-O3 --check-bounds=no`, # Optimize for speed with bounds checking disabled
    cpu_target = "native", # Optimize for the CPU of the current machine
    version = v"1.0.0", # Version number of the library
    compat_level = "major", # Set compatibility level to major
    script = nothing, # No additional scripts are executed
    base_sysimage = nothing # Do not base this sysimage on an existing one
)

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 2, 2024, 6:02am UTC](https://discourse.julialang.org/t/creating-a-library-with-packagecompiler-takes-ages/118927/2 "2024-09-02T06:02:04Z")

</div>

`-O3` looks a bit like overkill to me, I would use `-O2`

How much RAM do you have and how many cores?  
On Linux you might need 32 GB RAM if you have 8 cores for the parallel build process, if you have less RAM you must limit the number of cores that are used.

---

<div class="post-metadata">

**Author:** ![Theo-L](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theo-l/32/211742_2.png) [@Theo-L](https://discourse.julialang.org/u/Theo-L)\
**Post date:** [September 2, 2024, 6:34am UTC](https://discourse.julialang.org/t/creating-a-library-with-packagecompiler-takes-ages/118927/3 "2024-09-02T06:34:06Z")

</div>

Thanks a lot for the response @ufechner7. I’m creating the library in my local machine (4 cores/16GM RAM) on top of a docker container. I assume this is the problem. I could spin up an AWS instance with 16VCPUs and 32GBs of RAM. In that case what would be the ideal setting for JULIA\_NUM\_THREADS? Is there any other variable I need to set apart from this one?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 2, 2024, 6:55am UTC](https://discourse.julialang.org/t/creating-a-library-with-packagecompiler-takes-ages/118927/4 "2024-09-02T06:55:42Z")

</div>

[https://docs.julialang.org/en/v1/manual/environment-variables/#env-image-threads](https://docs.julialang.org/en/v1/manual/environment-variables/#env-image-threads)

If you are running very low on memory, set this variable to a lower value, e.g. to 1, 2 or 3 on a machine with 16GB RAM:  
`JULIA_IMAGE_THREAD`

But please check if you are really short of memory or not using `free -h` or `htop`.
