Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Swiftlint Analyzer uses large amounts of memory #2812
New Issue Checklist
Describe the bug
Running swiflint analyzer over 4000 swift files, with both the
Hey @jpsim so, I dug into this a bit and it turns out SourceKitten is leaking a lot of memory.
Take a look in the xcode memory graph debugger, you'll see leaked objects, they are named
I don't believe this can be fixed without breaking changes to SourceKitten. Should be fine, since SourceKitten is still
I think the best approach is to prevent the raw
I created a hacked together branch that proof of concepts this fix. Wanted to make sure I could run swiftlint analyzer without crashes and without large amounts of memory being used.
After this change memory usage dropped from 5GB for ~50 files to ~250MB.
I think there is still another another leak, because there are are lots of xpc strings, and memory usage was still slowly climbing. My guess is it's the keys for the dictionaries, but that's just a guess and memory usage was much more reasonable.
Also probably the root cause for: jpsim/SourceKitten#559
Amazing work @cltnschlosser
I think the other leak is "on purpose" where we cache byte-wise lookups into String since these are operations that we need to do so frequently: https://github.com/jpsim/SourceKitten/blob/0.23.2/Source/SourceKittenFramework/String+SourceKitten.swift#L71-L78
It'd be nice to find ways to speed up those operations sufficiently that we wouldn't need to maintain an indefinite cache.
I used SourceKitten master with swiftlint master to do an analyze run of 4000+ swift file codebase. Memory usage stayed below 3GB the whole time :) Also it didn't crash