-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Improve Linux performance #1577
Comments
We need to disable caching in |
Actually, enabling caching on Linux has a great impact: Just a naive implementation: diff --git a/Source/SourceKittenFramework/String+SourceKitten.swift b/Source/SourceKittenFramework/String+SourceKitten.swift
index c40cffe..14163a1 100644
--- a/Source/SourceKittenFramework/String+SourceKitten.swift
+++ b/Source/SourceKittenFramework/String+SourceKitten.swift
@@ -35,6 +35,10 @@ private let commentLinePrefixCharacterSet: CharacterSet = {
private var keyCacheContainer = 0
extension NSString {
+
+ static private var stringCache = [NSString: CacheContainer]()
+ static private var stringCacheLock = NSLock()
+
/**
CacheContainer caches:
@@ -181,7 +185,14 @@ extension NSString {
*/
private var cacheContainer: CacheContainer {
#if os(Linux)
- return CacheContainer(self)
+ NSString.stringCacheLock.lock()
+ defer { NSString.stringCacheLock.unlock() }
+ if let cache = NSString.stringCache[self] {
+ return cache
+ }
+ let cache = CacheContainer(self)
+ NSString.stringCache[self] = cache
+ return cache
#else
if let cache = objc_getAssociatedObject(self, &keyCacheContainer) as? CacheContainer {
return cache |
With the caching above, linting this repo takes 15.04s rather than the previous 3m23s. |
Yup,. The disadvantage of that implementation is that " |
True, but we already make that trade off on macOS. Linting this repo in debug mode with a dictionary cache above takes the same amount of memory as with ObjC associated objects (46MB). |
Certainly |
It probably is an issue, but not at the expense of performance. I'd say we should implement the dictionary based caching approach for now and eventually move that to File. |
I fully agree. 👍 |
86% of the time spent linting the SwiftLint repo on Linux is in CFStringFindCharacterFromSet.
Interactive version (open in a web browser): flamegraph.svg.zip
The text was updated successfully, but these errors were encountered: