Skip to content

Commit

Permalink
Remove locking overhead during serial analysis phase
Browse files Browse the repository at this point in the history
  • Loading branch information
ileitch committed Aug 20, 2024
1 parent 35dfcdb commit 531b0aa
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 123 deletions.
3 changes: 2 additions & 1 deletion Sources/Frontend/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ final class Scan {

let indexLogger = logger.contextualized(with: "index")
let plan = try driver.plan(logger: indexLogger)
let pipeline = IndexPipeline(plan: plan, graph: graph, logger: indexLogger)
let syncSourceGraph = SynchronizedSourceGraph(graph: graph)
let pipeline = IndexPipeline(plan: plan, graph: syncSourceGraph, logger: indexLogger)
try pipeline.perform()
logger.endInterval(indexInterval)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Indexer/IndexPipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import SourceGraph

public struct IndexPipeline {
private let plan: IndexPlan
private let graph: SourceGraph
private let graph: SynchronizedSourceGraph
private let logger: ContextualLogger

public init(plan: IndexPlan, graph: SourceGraph, logger: ContextualLogger) {
public init(plan: IndexPlan, graph: SynchronizedSourceGraph, logger: ContextualLogger) {
self.plan = plan
self.graph = graph
self.logger = logger
Expand Down
4 changes: 2 additions & 2 deletions Sources/Indexer/InfoPlistIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import SystemPackage

final class InfoPlistIndexer: Indexer {
private let infoPlistFiles: Set<FilePath>
private let graph: SourceGraph
private let graph: SynchronizedSourceGraph
private let logger: ContextualLogger

required init(infoPlistFiles: Set<FilePath>, graph: SourceGraph, logger: Logger = .init(), configuration: Configuration = .shared) {
required init(infoPlistFiles: Set<FilePath>, graph: SynchronizedSourceGraph, logger: Logger = .init(), configuration: Configuration = .shared) {
self.infoPlistFiles = infoPlistFiles
self.graph = graph
self.logger = logger.contextualized(with: "index:infoplist")
Expand Down
26 changes: 13 additions & 13 deletions Sources/Indexer/SwiftIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public struct IndexUnit {

final class SwiftIndexer: Indexer {
private let sourceFiles: [SourceFile: [IndexUnit]]
private let graph: SourceGraph
private let graph: SynchronizedSourceGraph
private let logger: ContextualLogger
private let configuration: Configuration

required init(
sourceFiles: [SourceFile: [IndexUnit]],
graph: SourceGraph,
graph: SynchronizedSourceGraph,
logger: ContextualLogger,
configuration: Configuration = .shared
) {
Expand Down Expand Up @@ -82,7 +82,7 @@ final class SwiftIndexer: Indexer {
let sourceFile: SourceFile

private let units: [IndexUnit]
private let graph: SourceGraph
private let graph: SynchronizedSourceGraph
private let logger: ContextualLogger
private let configuration: Configuration
private var retainAllDeclarations: Bool
Expand All @@ -91,7 +91,7 @@ final class SwiftIndexer: Indexer {
sourceFile: SourceFile,
units: [IndexUnit],
retainAllDeclarations: Bool,
graph: SourceGraph,
graph: SynchronizedSourceGraph,
logger: ContextualLogger,
configuration: Configuration
) {
Expand Down Expand Up @@ -202,11 +202,11 @@ final class SwiftIndexer: Indexer {
}

graph.withLock {
graph.addUnsafe(references)
graph.addUnsafe(newDeclarations)
graph.addWithoutLock(references)
graph.addWithoutLock(newDeclarations)

if retainAllDeclarations {
graph.markRetainedUnsafe(newDeclarations)
graph.markRetainedWithoutLock(newDeclarations)
}
}

Expand Down Expand Up @@ -252,10 +252,10 @@ final class SwiftIndexer: Indexer {
private func establishDeclarationHierarchy() {
graph.withLock {
for (parent, decls) in childDeclsByParentUsr {
guard let parentDecl = graph.explicitDeclaration(withUsr: parent) else {
guard let parentDecl = graph.explicitDeclarationWithoutLock(withUsr: parent) else {
if varParameterUsrs.contains(parent) {
// These declarations are children of a parameter and are redundant.
decls.forEach { graph.removeUnsafe($0) }
decls.forEach { graph.removeWithoutLock($0) }
}

continue
Expand All @@ -273,7 +273,7 @@ final class SwiftIndexer: Indexer {
private func associateLatentReferences() {
for (usr, refs) in referencesByUsr {
graph.withLock {
if let decl = graph.explicitDeclaration(withUsr: usr) {
if let decl = graph.explicitDeclarationWithoutLock(withUsr: usr) {
for ref in refs {
associateUnsafe(ref, with: decl)
}
Expand Down Expand Up @@ -454,14 +454,14 @@ final class SwiftIndexer: Indexer {
for param in params {
let paramDecl = param.makeDeclaration(withParent: functionDecl)
functionDecl.unusedParameters.insert(paramDecl)
graph.addUnsafe(paramDecl)
graph.addWithoutLock(paramDecl)

if retainAllDeclarations {
graph.markRetainedUnsafe(paramDecl)
graph.markRetainedWithoutLock(paramDecl)
}

if (functionDecl.isObjcAccessible && configuration.retainObjcAccessible) || ignoredParamNames.contains(param.name) {
graph.markRetainedUnsafe(paramDecl)
graph.markRetainedWithoutLock(paramDecl)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Indexer/XCDataModelIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import SystemPackage

final class XCDataModelIndexer: Indexer {
private let files: Set<FilePath>
private let graph: SourceGraph
private let graph: SynchronizedSourceGraph
private let logger: ContextualLogger

required init(files: Set<FilePath>, graph: SourceGraph, logger: Logger = .init(), configuration: Configuration = .shared) {
required init(files: Set<FilePath>, graph: SynchronizedSourceGraph, logger: Logger = .init(), configuration: Configuration = .shared) {
self.files = files
self.graph = graph
self.logger = logger.contextualized(with: "index:xcdatamodel")
Expand Down
4 changes: 2 additions & 2 deletions Sources/Indexer/XCMappingModelIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import SystemPackage

final class XCMappingModelIndexer: Indexer {
private let files: Set<FilePath>
private let graph: SourceGraph
private let graph: SynchronizedSourceGraph
private let logger: ContextualLogger

required init(files: Set<FilePath>, graph: SourceGraph, logger: Logger = .init(), configuration: Configuration = .shared) {
required init(files: Set<FilePath>, graph: SynchronizedSourceGraph, logger: Logger = .init(), configuration: Configuration = .shared) {
self.files = files
self.graph = graph
self.logger = logger.contextualized(with: "index:xcmappingmodel")
Expand Down
4 changes: 2 additions & 2 deletions Sources/Indexer/XibIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import SystemPackage

final class XibIndexer: Indexer {
private let xibFiles: Set<FilePath>
private let graph: SourceGraph
private let graph: SynchronizedSourceGraph
private let logger: ContextualLogger

required init(xibFiles: Set<FilePath>, graph: SourceGraph, logger: Logger = .init(), configuration: Configuration = .shared) {
required init(xibFiles: Set<FilePath>, graph: SynchronizedSourceGraph, logger: Logger = .init(), configuration: Configuration = .shared) {
self.xibFiles = xibFiles
self.graph = graph
self.logger = logger.contextualized(with: "index:xib")
Expand Down
Loading

0 comments on commit 531b0aa

Please sign in to comment.