Skip to content

Switch to the mimalloc allocator - #484

Merged
SpaceManiac merged 1 commit into
SpaceManiac:masterfrom
ZeWaka:mimalloc
Oct 3, 2026
Merged

SpaceManiac merged 1 commit into
SpaceManiac:masterfrom
ZeWaka:mimalloc

Conversation

@ZeWaka

@ZeWaka ZeWaka commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Switches the langserver from the default system allocator to mimalloc.
Gives a great speedup in parse time and a decrease in memory usage.

Mimalloc is more designed for the tiny short-lived allocations we're doing with the parser.
I chose v2 because v3 actually uses more memory. I looked into some other allocators but they didn't give much gains.

Mimalloc does hold onto freed pages until another alloc or asked, so we force a collect at the end of heavy operations where there wouldn't be another alloc (server goes idle).

Median of 3 runs each on my local Windows machine:

Codebase Build Parse Load time (parse + refs + dreamchecker) Private memory Working set Peak working set
goonstation before 3.01 s 3.79 s 503 MB 482 MB 522 MB
goonstation after 1.81 s (−40%) 2.35 s (−38%) 434 MB (−14%) 425 MB (−12%) 483 MB (−7%)
tgstation before 4.07 s 5.23 s 659 MB 632 MB 691 MB
tgstation after 2.38 s (−42%) 3.10 s (−41%) 566 MB (−14%) 553 MB (−13%) 633 MB (−8%)

Speedup is less on Linux (Well, WSL) because their allocator is less shite. More like 20% loading and memory reduction.

Sidenote:

I think even more gains could be had by splitting proc body parsing (about 50% of the used memory) out since the only things that use them are dreamchecker and Find References. Dropping it after dreamchecker and lazily reparsing on Find-Reference could be worth it. Yep, and didn't need to do reparsing lazily: #486

@ZeWaka
ZeWaka marked this pull request as ready for review September 30, 2026 03:48
@ZeWaka ZeWaka changed the title switch to the mimalloc allocator Switch to the mimalloc allocator Oct 1, 2026
@ZeWaka

ZeWaka commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Your choice if you want to mark #113 fixed by this (or a potential future proc body parsing split PR).

@SpaceManiac

Copy link
Copy Markdown
Owner

Benched on Linux, also including dreamchecker CLI. Improvements are big on musl, smaller but still meaningful on glibc.

codebase libc alloc dc time (s) ls parse (s) ls total (s) ls mem (K)
tgstation musl default 4.63 3.551 4.71 652060
tgstation musl mi 2.90 (-37%) 2.372 (-33%) 2.959 (-37%) 568260 (-13%)
tgstation gnu default 2.86 2.092 2.694 695404
tgstation gnu mi 2.36 (-17%) 1.795 (-14%) 2.275 (-16%) 568296 (-18%)
goonstation musl default 3.57 2.692 3.606 475632
goonstation musl mi 2.27 (-36%) 1.841 (-32%) 2.319 (-36%) 420664 (-12%)
goonstation gnu default 2.15 1.563 2.026 527452
goonstation gnu mi 1.83 (-15%) 1.366 (-13%) 1.740 (-14%) 420656 (-20%)

I might want to switch release builds off musl if I can! Here's the musl->glibc comparison:

codebase alloc dc time ls parse ls total ls mem
tgstation default 38% 41% 43% -7%
tgstation mi 19% 24% 23% 0%
goonstation default 40% 42% 44% -11%
goonstation mi 19% 26% 25% 0%

@SpaceManiac
SpaceManiac merged commit c163286 into SpaceManiac:master Oct 3, 2026
1 check passed
@ZeWaka
ZeWaka deleted the mimalloc branch October 3, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants