# Precompiling LanguageServer.runserver() with PrecompileTools.jl

**URL:** <https://discourse.julialang.org/t/precompiling-languageserver-runserver-with-precompiletools-jl/97926>\
**Category:** Performance\
**Tags:** precompilation, vscode, languageserver\
**Created:** [April 26, 2023, 3:39am UTC](https://discourse.julialang.org/t/precompiling-languageserver-runserver-with-precompiletools-jl/97926 "2023-04-26T03:39:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [April 26, 2023, 3:39am UTC](https://discourse.julialang.org/t/precompiling-languageserver-runserver-with-precompiletools-jl/97926/1 "2023-04-26T03:39:14Z")

</div>

After a [conversation on Slack](https://julialang.slack.com/archives/C013J5F9USH/p1682472242561679), with [Tom McLaughlin](https://discourse.julialang.org/u/thomasjm), I decided to try adding some precompilation to LanguageServer.jl. Tom had noticed about 10 second lag in the execution of `LanguageServer.runserver()`. This is part of julia-vscode, so a speed up here would be quite beneficial.

Before the change, `runserver()` would take about 14 seconds to compile on my computer after each time the package is loaded.

```julia
julia> @time runserver()
...
 30.517983 seconds (6.45 M allocations: 370.912 MiB, 1.60% gc time, 46.59% compilation time)

julia> 30.517983*0.4659
14.2183282797

```

After the change, `runserver()`, compilation takes 1.4 seconds.

```julia
julia> @time runserver()
...
 10.929685 seconds (3.77 M allocations: 198.920 MiB, 3.33% gc time, 12.61% compilation time)

julia> 10.929685 * 0.1261
1.3782332784999998

```

Load time while running `using LanguageServer` increased from ~20 ms to ~550 ms. The compiled cache shared library went from 2.4 MB to 13 MB.

The substantive part of my change is as follows. Can you do better?

```julia
using PrecompileTools
...
@setup_workload begin
    iob = IOBuffer()
    println(iob)
    @compile_workload begin
        runserver(iob)
    end
end
precompile(runserver, ())

```

There’s a lot to improve. Running this during precompilation involves network activity for one.

Here’s the pull request:

> <https://github.com/julia-vscode/LanguageServer.jl/pull/1218>
>
> Add PrecompileTools to and precompile \`runserver\`.
> 
> For every PR, please check… the following:
> \- \[x\] End-user documentation check. If this PR requires end-user documentation in the Julia VS Code extension docs, please add that at https://github.com/julia-vscode/docs.
> \- \[\] Changelog mention. If this PR should be mentioned in the CHANGELOG for the Julia VS Code extension, please open a PR against https://github.com/julia-vscode/julia-vscode/blob/master/CHANGELOG.md with those changes.

In case you missed the announcement, [PrecompileTools.jl is the new name of SnoopPrecompile.jl](https://discourse.julialang.org/t/ann-snoopprecompile-precompiletools/97882).
