Skip to content

Commit 5846c2f

Browse files
committed
full-analysis: Clear Pkg registry cache after environment operations
Clear `Pkg.Registry.REGISTRY_CACHE` in finally blocks after package environment operations to reduce memory footprint. This is a temporary workaround using internal API and should be removed once a proper solution for module/CodeInstance garbage collection is available in Julia runtime.
1 parent f9dd15b commit 5846c2f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/analysis/full-analysis.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ function resolve_analysis_request(server::Server, request::AnalysisRequest)
306306
if prev_result !== nothing
307307
cleanup_prev_methods(prev_result)
308308
end
309+
# HACK This is a terrible hack to reduce Pkg.jl's memory footprint:
310+
# This behavior should really be implemented as an environment variable that Pkg.jl understands,
311+
# or perhaps this cache itself should be optimized.
312+
empty!(Pkg.Registry.REGISTRY_CACHE)
309313
failed && @goto next_request
310314
end
311315
tm = round(time() - s, digits=2)
@@ -743,6 +747,11 @@ function ensure_instantiated!(server::Server, env_path::String)
743747
The package will be analyzed as a script, which may result in incomplete diagnostics.
744748
See the language server log for details.
745749
It is recommended to fix your package environment setup and restart the language server.""")
750+
finally
751+
# HACK This is a terrible hack to reduce Pkg.jl's memory footprint:
752+
# This behavior should really be implemented as an environment variable that Pkg.jl understands,
753+
# or perhaps this cache itself should be optimized.
754+
empty!(Pkg.Registry.REGISTRY_CACHE)
746755
end
747756
else
748757
is_instantiated = try
@@ -751,6 +760,11 @@ function ensure_instantiated!(server::Server, env_path::String)
751760
@error "Failed to create cache for package environment" env_path
752761
Base.showerror(stderr, e, catch_backtrace())
753762
false
763+
finally
764+
# HACK This is a terrible hack to reduce Pkg.jl's memory footprint:
765+
# This behavior should really be implemented as an environment variable that Pkg.jl understands,
766+
# or perhaps this cache itself should be optimized.
767+
empty!(Pkg.Registry.REGISTRY_CACHE)
754768
end
755769
if !is_instantiated
756770
show_warning_message(server, """

0 commit comments

Comments
 (0)