Skip to content

Commit

Permalink
Various optimizations (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch authored Jul 3, 2023
1 parent e5d6f5a commit 3091f5f
Show file tree
Hide file tree
Showing 25 changed files with 175 additions and 129 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ileitch/swift-indexstore",
"state" : {
"revision" : "314cc506ab5e782a9fcf75bf9c82c56f581f8fef",
"version" : "9.0.0"
"revision" : "4e20a3b2d8bb9bae8ebffb43515987eb6eb5efd8",
"version" : "9.0.2"
}
},
{
Expand All @@ -77,8 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/tuist/xcodeproj",
"state" : {
"revision" : "5fdac93cb4a7fd4bad5ac2da34e5bc878263043f",
"version" : "8.10.0"
"revision" : "59c7f8d4201a7bd37ef509edebd5777811c7de78",
"version" : "8.11.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/jpsim/Yams", from: "5.0.0"),
.package(url: "https://github.com/tadija/AEXML", from: "4.0.0"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.package(url: "https://github.com/ileitch/swift-indexstore", from: "9.0.0"),
.package(url: "https://github.com/ileitch/swift-indexstore", from: "9.0.2"),
.package(url: "https://github.com/peripheryapp/swift-syntax", exact: "1.0.2"),
.package(url: "https://github.com/ileitch/swift-filename-matcher", from: "0.0.0"),
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/Frontend/Commands/ScanBehavior.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class ScanBehavior {

do {
results = try block(project)
let interval = logger.beginInterval("scan:result:output")
let interval = logger.beginInterval("result:output")
let filteredResults = OutputDeclarationFilter().filter(results)
let sortedResults = filteredResults.sorted { $0.declaration < $1.declaration }
let output = try configuration.outputFormat.formatter.init().format(sortedResults)
Expand Down
15 changes: 14 additions & 1 deletion Sources/Frontend/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,36 @@ final class Scan {
logger.info("\(asterisk) Inspecting project...")
}

let driverPrepareInterval = logger.beginInterval("driver:prepare")
let driver = try project.driver()
logger.endInterval(driverPrepareInterval)
let driverBuildInterval = logger.beginInterval("driver:build")
try driver.build()
logger.endInterval(driverBuildInterval)

let indexInterval = logger.beginInterval("index")
if configuration.outputFormat.supportsAuxiliaryOutput {
let asterisk = colorize("*", .boldGreen)
logger.info("\(asterisk) Indexing...")
}

let graph = SourceGraph.shared
try driver.index(graph: graph)
logger.endInterval(indexInterval)

let analyzeInterval = logger.beginInterval("analyze")
if configuration.outputFormat.supportsAuxiliaryOutput {
let asterisk = colorize("*", .boldGreen)
logger.info("\(asterisk) Analyzing...")
}

try SourceGraphMutatorRunner.perform(graph: graph)
return ScanResultBuilder.build(for: graph)
logger.endInterval(analyzeInterval)

let resultInterval = logger.beginInterval("result:build")
let result = ScanResultBuilder.build(for: graph)
logger.endInterval(resultInterval)

return result
}
}
4 changes: 2 additions & 2 deletions Sources/PeripheryKit/Indexer/Declaration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public final class Declaration {
var isImplicit: Bool = false
var isObjcAccessible: Bool = false

private let identifier: String
private let identifier: Int

var ancestralDeclarations: Set<Declaration> {
var maybeParent = parent
Expand Down Expand Up @@ -236,7 +236,7 @@ public final class Declaration {
self.kind = kind
self.usrs = usrs
self.location = location
self.identifier = usrs.joined()
self.identifier = usrs.hashValue
}

func isDeclaredInExtension(kind: Declaration.Kind) -> Bool {
Expand Down
28 changes: 28 additions & 0 deletions Sources/PeripheryKit/Indexer/JobPool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,32 @@ struct JobPool<T> {

return results
}

func compactMap<R>(_ block: @escaping (T) throws -> R?) throws -> [R] {
var error: Error?
var results: [R] = []
let lock = UnfairLock()

DispatchQueue.concurrentPerform(iterations: jobs.count) { idx in
guard error == nil else { return }

do {
let job = jobs[idx]
if let result = try block(job) {
lock.perform {
results.append(result)
}
}
} catch let e {
error = e
}
}

if let error = error {
throw error
}

return results
}

}
6 changes: 3 additions & 3 deletions Sources/PeripheryKit/Indexer/Reference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ public final class Reference {
public let usr: String
public var role: Role = .unknown

private let identifier: String
private let identifier: Int

init(kind: Kind, usr: String, location: SourceLocation, isRelated: Bool = false) {
self.kind = kind
self.usr = usr
self.isRelated = isRelated
self.location = location
self.identifier = "\(usr.hashValue)-\(location.hashValue)-\(isRelated.hashValue)"
self.identifier = [usr.hashValue, location.hashValue, isRelated.hashValue].hashValue
}

var descendentReferences: Set<Reference> {
Set(references.flatMap { $0.descendentReferences }).union(references)
references.flatMapSet { $0.descendentReferences }.union(references)
}
}

Expand Down
13 changes: 5 additions & 8 deletions Sources/PeripheryKit/Indexer/SourceLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ public class SourceLocation {
public let line: Int
public let column: Int

private let identifier: Int

init(file: SourceFile, line: Int, column: Int) {
self.file = file
self.line = line
self.column = column
self.identifier = [file.hashValue, line, column].hashValue
}

// MARK: - Private
Expand All @@ -28,19 +31,13 @@ public class SourceLocation {

extension SourceLocation: Equatable {
public static func == (lhs: SourceLocation, rhs: SourceLocation) -> Bool {
let fileIsEqual = lhs.file == rhs.file
let lineIsEqual = lhs.line == rhs.line
let columnIsEqual = lhs.column == rhs.column

return fileIsEqual && lineIsEqual && columnIsEqual
lhs.identifier == rhs.identifier
}
}

extension SourceLocation: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(file)
hasher.combine(line)
hasher.combine(column)
hasher.combine(identifier)
}
}

Expand Down
Loading

0 comments on commit 3091f5f

Please sign in to comment.