Ask
147
@flakey_test ·

gopls eats memory on our monorepo and completions take seconds, what do you actually turn off?

Roughly 600k lines of Go in a single module, one repo, VS Code on a 16GB laptop. Opening the repo root has gopls climbing to several gigabytes within a few minutes and then completions start taking two or three seconds each, which makes editing genuinely unpleasant. I have already tried restarting the language server on a hotkey, which helps for about twenty minutes. Looking for settings people actually changed rather than a link to the whole options list.

10 answers Share
Report

Answering anonymously — a moderator will review it first.

  • @two_vcpu_club · 3d ago

    I measured this properly because I was about to buy a laptop over it. Baseline on our monorepo, opened at the root, peaked around 6GB resident and completions averaged just under two seconds after the first hour. Opening a single service directory instead brought it to well under 2GB with sub-300ms completions on the same machine.

    The interesting part is that turning off analyses on top of that made almost no additional difference once the workspace was scoped correctly. Scope first, then tune. Tuning a badly scoped workspace is rearranging deck chairs.

    132
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @chmod_confused · 3d ago

    Three settings that measurably helped on our repo, in the order they helped. Turn off the extra static analysis passes, which run on top of the type checking and are the most expensive optional work gopls does. Turn off the code lens features you never click, particularly the run-test-above-every-function ones. And disable automatic imports scanning of the whole module if your editor is doing that on every keystroke.

    After those three, peak memory on our repo dropped by roughly a third and completion latency became tolerable again. The analysis passes were by far the largest single contributor.

    148
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @parquet_pile · 2d ago · 3 replies

    I want to push back on the turn-off-the-analyses advice, because it is treating a symptom and you lose real value. In our case the actual culprit was a stale build cache and a generated code directory that nothing excluded, so gopls was type checking several hundred thousand lines of generated protobuf output on every change. Excluding the generated directories from the workspace and clearing the build cache fixed it more thoroughly than any setting did, and we kept the static checks. Look at what is actually in your 600k lines before you disable the tooling you presumably turned on for a reason.

    114
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @flakey_test · 3d ago

      We have a very large generated client in tree. This is now the first thing I am checking tomorrow.

      38
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @chmod_confused · 3d ago

      That is a good catch and worth checking first. Our generated code sits outside the module so it never showed up for us, but if yours is inside it would dominate everything.

      53
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @csv_apologist · yesterday · 3 replies

    Stop opening the repo root. Open the subdirectory you are actually working in as the workspace folder and gopls only builds the graph for what is reachable from there. On a monorepo that is usually the single biggest change available to you, and it costs nothing.

    176
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
    • @cast_iron_carl · 4d ago

      You keep definitions into anything your package imports, because that is in the build graph. What you lose is jumping into unrelated services you were never going to edit anyway.

      79
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
    • @flakey_test · 2d ago

      That does mean losing go-to-definition into other parts of the repo though, which is half of why I open the root.

      24
      Share
      Reply

      Answering anonymously — a moderator will review it first.

      Report
  • @quietpackets · 3d ago

    I made this worse for a year by running three extensions that each did their own analysis on save, all of which duplicated work gopls was already doing. Linting on save through a separate extension, a formatter extension that shelled out on every keystroke, and a test runner that watched the whole tree. Removing two of them and letting gopls do its job single-handedly halved my CPU and I have never missed either.

    91
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report
  • @edge_runtime_bo · 2h ago

    Scope the workspace, exclude generated code, drop the optional analyses, and keep the language server on a recent version. In that order, and stop after whichever one fixes it.

    1
    Share
    Reply

    Answering anonymously — a moderator will review it first.

    Report