summaryrefslogtreecommitdiff
path: root/runtime/js/99_main.js
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-04-06 19:22:37 -0700
committerGitHub <noreply@github.com>2024-04-06 19:22:37 -0700
commitb74a4f29f20c2435ea7c6d192353c1e99760edb0 (patch)
treec7b07b27c9703fcda2fc28310e2196740ef34284 /runtime/js/99_main.js
parentf9f37963b70948f51334ded1657546e614cfa0a6 (diff)
perf(lsp): Don't retain `SourceFileObject`s in `sourceFileCache` longer than necessary (#23258)
The TS language service requests source files via [getSourceFile](https://github.com/nathanwhit/deno/blob/7a25fd5ef0a82c2aac76594ccd467e9210e92b80/cli/tsc/99_main_compiler.js#L560). In that function, we [unconditionally add](https://github.com/nathanwhit/deno/blob/7a25fd5ef0a82c2aac76594ccd467e9210e92b80/cli/tsc/99_main_compiler.js#L613-L614) the source file to our sourceFileCache. The issue is that we only remove things from that cache if the source file [becomes out of date](https://github.com/nathanwhit/deno/blob/7a25fd5ef0a82c2aac76594ccd467e9210e92b80/cli/tsc/99_main_compiler.js#L777-L783). For files that don't get changed, we keep them in the cache indefinitely. So sometimes we keep SourceFile objects from being GC'ed because they're retained in our cache, even though TS doesn't refer to them any more. I see this in pretty much all of the heap snapshots I've taken. --- The fix here is pretty direct - just store weak references to the sourcefiles in the cache. It doesn't really change our caching behavior, it just prevents us from being the only retainer of a `SourceFile`. I also split the `sourceFileCache` into a separate cache just for assets, as we rely on those being alive. The simpler fix is to only cache assets, but presumably that has a perf impact. --- In local testing, this PR reduced the size of the JS heap by about 1 GB when using `deno lsp` in the Typescript repo.
Diffstat (limited to 'runtime/js/99_main.js')
0 files changed, 0 insertions, 0 deletions