Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-562] Memory leak in SourceKitService since using Swift name lookup tables by default #43179

Closed
swift-ci opened this issue Jan 17, 2016 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-562
Radar rdar://problem/24225173
Original Reporter Pascal (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment
  • OSX 10.11.2

  • Xcode 7.2 and 7.3

  • Any Swift snapshot since 22.12.15

Additional Detail from JIRA
Votes 0
Component/s Compiler, Source Tooling
Labels Bug, ClangImporter
Assignee @DougGregor
Priority Medium

md5: 8fe65d0623d257e3bb29cb40c115af2c

Issue Description:

A memory leak in SourceKitService was introduced between snapshot 18.12.15 and 22.12.15.

Here are my findings:

  • Some git-bisecting led to the first introduction in commit:
    ["Clang importer: enable the Swift name lookup tables by default." | ae6b41d]

  • Further changes were made in commit:
    ["Clang importer: delete most of the old name lookup path. NFC" | 1989475]

  • There were no significant changes made to SourceKit between both snapshots, only typo fixes.

  • Profiling SourceKitService with Instruments (Leaks, VM Tracker) and observing the open files in Activity Monitor shows lots of duplicate open files.

Steps to reproduce

  • Select any Swift Snapshot since 22.12.15. Xcode version does not matter, SourceKitService is independent from Xcode.

  • Create a new Swift project (or use an existing one). Size of the project doesn't matter. The only part that influences how fast memory grows is the number of imported modules. The "Hello, World!" default file with Foundation imported should be enough.

  • Monitor memory usage of SourceKitService.

  • Change anything in the source file (holding space should be enough). After a few seconds SourceKitService uses about 1GB memory

Helpful debugging tips

I don't know enough about XPC services and Google didn't produce any helpful tips, so here is the best way I found to get more information about the leaks. Maybe these tips are helpful for others:

Attaching Instruments to SourceKitService is not really that helpful because it is not linked to CoreFoundation.

To get more detailed information about the leaks (stack traces) do the following:
Use the MallocStackLogging environment variable by adding this to the XPCService dictionary

<dict>
    <key>EnvironmentVariables</key>
    <dict>
        <key>MallocStackLogging</key>
        <string>1</string>
    </dict>
</dict>
</plist>

in $SNAPSHOT/usr/lib/sourcekitd.framework/Versions/A/XPCServices/SourceKitService.xpc/Contents/Info.plist.
I attached the Info.plist I used.
Then you can use the command line tools malloc_history and leaks on the SourceKitService process.

@tkremenek
Copy link
Member

Cloned to <rdar://problem/24225173>

@DougGregor
Copy link
Member

Fixed in 679ee11 and cherry-picked into swift-2.2-branch as 01a3983

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants