Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

fix: memory-leak due to unbound type-parameter recursion#320

Closed
PatrickHaecker wants to merge 1 commit into
julia-vscode:masterfrom
PatrickHaecker:memory_leak_unbounded_recursion
Closed

fix: memory-leak due to unbound type-parameter recursion#320
PatrickHaecker wants to merge 1 commit into
julia-vscode:masterfrom
PatrickHaecker:memory_leak_unbounded_recursion

Conversation

@PatrickHaecker

Copy link
Copy Markdown

FakeTypeName expanded nested type parameters without a depth limit, so type-domain packages (e.g. TypeDomainNaturalNumbers.jl) produced multi-GB cache files that exhausted memory on load OOMing the machine.

To fix this, cap recursion at MAX_TYPE_PARAMETER_DEPTH (25), storing the type name only past that depth, and add a regression test.

@davidanthoff: This is kind of an "Make VS Code work again" fix, because without it, VS Code was getting closer and closer to being unusable for the last weeks. It seemed to worsen over time, so pressure was large enough to check how to fix this.

Claude Opus 4.8 helped in developing this fix

@PatrickHaecker
PatrickHaecker marked this pull request as draft July 5, 2026 04:40
@PatrickHaecker

PatrickHaecker commented Jul 5, 2026

Copy link
Copy Markdown
Author

I wanted to bring this PR out, before the OOM manager is doing its work again. However, turned out, that this does not reliably enough solve the overall problem. I'll check what the the remaining problem is. Setting to draft until I can confirm, that memory usage is sane again on my machine.

FakeTypeName expanded a type's parameters recursively with no size bound.
A few types explode into enormous trees: type-domain packages whose types
recurse into themselves (e.g. TypeDomainNaturalNumbers — naturals as nested
types, rationals as continued fractions), and even some Base/LinearAlgebra
signatures whose `where`-bounded `Union`s reach tens of thousands of nodes.
This produced multi-gigabyte cache files (2.2 GB for TypeDomainNaturalNumbers)
that exhausted memory — OOMing the machine — when read back into the store.

Cap expansion with a per-type budget of expanded DataTypes
(MAX_EXPANDED_TYPES = 128): once it is spent, a type's remaining parameters
are dropped and only its name is kept. The budget bounds any shape of
explosion (depth, width, or indirect recursion through variable bounds),
while ordinary types stay far below it and are unaffected.
@PatrickHaecker
PatrickHaecker force-pushed the memory_leak_unbounded_recursion branch from ed3c425 to 221294f Compare July 5, 2026 06:25
@davidanthoff

Copy link
Copy Markdown
Member

This package is deprecated, we moved all the functionality into JuliaWorkspaces.jl. If this is also an issue there (presumably it is), then it would make most sense to have a PR over there.

@PatrickHaecker

Copy link
Copy Markdown
Author

Thanks, @davidanthoff. I really lost track with all the components involved in the VS Code plugin. Closing this here and trying to carry over the fix.

@PatrickHaecker

Copy link
Copy Markdown
Author

@davidanthoff, ok, done: JuliaWorkspaced#112

pfitzseb pushed a commit to julia-vscode/JuliaWorkspaces.jl that referenced this pull request Jul 6, 2026
FakeTypeName expanded a type's parameters recursively with no size bound.
A few types explode into enormous trees: type-domain packages whose types
recurse into themselves (e.g. TypeDomainNaturalNumbers — naturals as nested
types, rationals as continued fractions), and even some Base/LinearAlgebra
signatures whose `where`-bounded `Union`s reach tens of thousands of nodes.
This produced multi-gigabyte cache files (2.2 GB for TypeDomainNaturalNumbers)
that exhausted memory — OOMing the machine — when read back into the store.

Cap expansion with a per-type budget of expanded DataTypes
(MAX_EXPANDED_TYPES = 128): once it is spent, a type's remaining parameters
are dropped and only its name is kept. The budget bounds any shape of
explosion (depth, width, or indirect recursion through variable bounds),
while ordinary types stay far below it and are unaffected. Add a regression
test.

Ported from julia-vscode/SymbolServer.jl#320 (SymbolServer.jl is deprecated;
the code now lives here under shared/symbolserver/).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants