fix(linter): prevent memory leak in resolver cache during language server usage#12674
Closed
fix(linter): prevent memory leak in resolver cache during language server usage#12674
Conversation
Contributor
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
…urce Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Evaluate @oxc-project/oxc/issues/10627 and find where memory can leak in @oxc-project/oxc/files/crates/oxc_language_server and @oxc-project/oxc/files/crates/oxc_linter
fix(linter): prevent memory leak in resolver cache during language server usage
Jul 31, 2025
CodSpeed Instrumentation Performance ReportMerging #12674 will not alter performanceComparing Summary
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The oxc language server was experiencing severe memory leaks when using the import plugin, with memory usage growing by 1-40MB per file open/close cycle and reaching several gigabytes over time. This was reported in issue #10627 where users observed the
oxc_language_serverprocess consuming 6.7GB of memory after an hour of usage.Root Cause
Through ASAN analysis by @Brooooooklyn, the leak was traced to
oxc_resolver::fs_cache::FsCachewhich caches filesystem metadata globally for performance optimization. In the language server context, where files are processed repeatedly viaRuntime::run_source(), this cache would accumulate indefinitely without cleanup:crates/oxc_linter/src/service/runtime.rs:976whereresolver.resolve(dir, specifier)is calledSolution
Added strategic cache clearing at the end of
Runtime::run_source()method:This approach:
clear_cache()API provided by oxc_resolverTesting
Impact
This fix resolves the memory leak that was making the oxc language server unusable for extended development sessions, particularly when working with React/JSX projects that heavily use imports.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.