lsp

Eric Dvorsak 2025-12-15T11:46:15.790919Z

What is costing so much ram in clojure-lsp? I have some clojure-lsp processes that take like 5 GB of ram, It's my bottleneck these days šŸ˜„

Eric Dvorsak 2025-12-16T12:21:30.063549Z

in the meantime šŸ˜„

ericdallo 2025-12-15T12:02:22.925639Z

Code analysis that come from kondo during startup, it depends how big is your project, you can tune to disable keyword analysis or symbols for example but that will disable features for those

Eric Dvorsak 2025-12-15T12:08:57.089369Z

so it's just at the beginning and then the jvm greedily hold on to the ram?

Eric Dvorsak 2025-12-15T12:09:32.536049Z

would be awesome if clojure-lsp was a unique process then šŸ˜…

borkdude 2025-12-15T12:10:14.205429Z

clojure-lsp holds the data structures in memory

ericdallo 2025-12-15T12:11:04.514789Z

Also having a single process would not help that much as it would hold different projects data, summing everything in a single process besides being harder to manage, although its an old idea that it's not trivial to support

borkdude 2025-12-15T12:12:16.269449Z

(I must admit I maxed out the RAM for my new machine with clojure-lsp in mind šŸ˜… )

Eric Dvorsak 2025-12-15T12:13:05.450519Z

yeah me too I'm really pissed my motherboard has issues with 256gb so I had to downgrade to 128gb and now it freezes but because I reache it all the time

šŸ‘€ 1
borkdude 2025-12-15T12:13:29.372619Z

128gb isn't enough...?

borkdude 2025-12-15T12:13:51.038909Z

then clojure-lsp likely won't be the issue unless you have dozens of projects?

Eric Dvorsak 2025-12-15T12:14:02.635819Z

yes I do

ericdallo 2025-12-15T12:14:18.708109Z

Yeah, I have 16GB ddr5 and it's not a issue, you must be using multiple projects at the same time?

ericdallo 2025-12-15T12:14:51.851009Z

And I use 3-4 projects at the same time

Eric Dvorsak 2025-12-15T12:15:27.340779Z

Eric Dvorsak 2025-12-15T12:17:05.067859Z

damn emacs starting a lsp-sever every time I open a file in a project šŸ˜„

ericdallo 2025-12-15T12:18:20.885999Z

Sounds like misconfigured project root

borkdude 2025-12-15T12:18:34.449769Z

Wow, that explains it

Eric Dvorsak 2025-12-15T12:19:00.000489Z

wdym misconfigured project root?

Eric Dvorsak 2025-12-15T12:20:02.994399Z

I can imagine that the fact that my main project is cloning some core libraries for facilitate editing the code adds up to how much it has to index?

ericdallo 2025-12-15T12:20:06.657659Z

If you open files of the same project, lsp-mode should use the same running server

Eric Dvorsak 2025-12-15T12:20:21.002349Z

no but it is the same project but different worktrees

ericdallo 2025-12-15T12:20:40.407689Z

Like a mono repo?

ericdallo 2025-12-15T12:20:59.937959Z

maybe try using a single clojure-lsp for the whole thing

Eric Dvorsak 2025-12-15T12:21:20.047989Z

no worktrees are like a branch but instead of checking out and screwing your current wip you go into a different directory

ericdallo 2025-12-15T12:21:26.956109Z

Just having a single project root with configured settings for other source paths, dunno, would need to understand better your arch

ericdallo 2025-12-15T12:22:15.450349Z

It's not clear yet to meet how your folders look like, if there is more than a deps.edn/project.clj etc

borkdude 2025-12-15T12:24:36.419869Z

You could try lsp-remove folders

Eric Dvorsak 2025-12-15T12:26:09.704529Z

one oddity is that I clone multiple projects in a .local-repos to make it easier to read the source and edit it

Eric Dvorsak 2025-12-15T12:26:25.912689Z

that may explain the size of some lsp instances

lassemaatta 2025-12-15T12:43:02.162249Z

one of the reasons I haven't really explored git worktrees is precisely this, as I would expect to get a LSP process per worktree. Just like if you checked out the same git repo multiple times into separate directories (e.g. for different branches) and then opened each as separate projects.

Eric Dvorsak 2025-12-15T12:54:55.948519Z

exactly and it kinda sucks because fundamentally there isn't much difference between 2 worktress, so with clojure immutable datastructure inner workings it could even be really cheap to have worktrees if it was natively understood by clojure-lsp

Eric Dvorsak 2025-12-15T12:55:22.785569Z

baically just the diffs

ericdallo 2025-12-15T12:57:24.378799Z

hehe unfortunately it's not that easy, but having a common project root would be the start for that

lassemaatta 2025-12-15T13:02:33.995189Z

I would imagine efficiently constructing and sharing the analysis data between two arbitrary projects (be they similar worktrees of a single codebase or totally different projects) would be almost impossible šŸ™‚ But sometimes I've naively wondered if the startup time could be improved by hashing the namespace tree and caching the analysis or parts of it.

ericdallo 2025-12-15T13:29:11.429369Z

The fun thing is: we already do that, we cache analysis by file hashes

ericdallo 2025-12-15T13:29:35.979739Z

@jacob.maine helped with that years ago, and helped a lot the performance

šŸŽ‰ 1
1
ericdallo 2025-12-15T14:02:01.688569Z

I noticed tho we only do that for external analysis https://github.com/clojure-lsp/clojure-lsp/blob/f555e4b89a1a3aa8aa9f66809f0d5e4dc034c61d/lib/src/clojure_lsp/startup.clj#L127, IIRC it was for consistency to avoid cache something of the project that might changed, but not sure that's something that would happen

lassemaatta 2025-12-15T15:52:39.412839Z

if the infrastructure is already(?) there, I wonder how much work would it require to extend that to cover project files too? perhaps guarded by a setting so that users can opt-in, in case there are issues. we have thousands of namespaces in one of our projects, some of which haven't been touched in years (or decades), so it would be cool to see how much of an effect such caching might have.

ericdallo 2025-12-15T15:53:18.530609Z

yeah agree, we can explore that

šŸ‘ 1
2025-12-15T18:20:07.921049Z

fwiw, I’m using worktrees and have similar issues. The worktrees often share 99%+ code.

āž• 1