-
Notifications
You must be signed in to change notification settings - Fork 2
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 performance of DependencyBuilder #226
Conversation
c85f7c8
to
7307774
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! 🙏
@@ -97,3 +120,12 @@ public struct OverrideBehavior { | |||
return NSClassFromString("XCTestCase") != nil | |||
} | |||
} | |||
|
|||
public struct ModuleAssemblyFlags: OptionSet { | |||
public let rawValue: Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public let rawValue: Int | |
public let rawValue: UInt |
@@ -40,6 +45,24 @@ public extension ModuleAssembly { | |||
return self.resolverType == $0.resolverType | |||
} | |||
} | |||
|
|||
static var _assemblyFlags: [ModuleAssemblyFlags] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static var _assemblyFlags: [ModuleAssemblyFlags] { | |
static let _assemblyFlags: [ModuleAssemblyFlags] = { |
Can we make this a computed static property so it is only calculated once per assembly type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't add a static let in an extension
if self is any AutoInitModuleAssembly.Type { | ||
result.append(.autoInit) | ||
} | ||
if self is any AbstractAssembly.Type { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like for these is
checks we are just moving the call site? Is there some other way that this causes a performance improvement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fallback, it only gets hit if a code gen version isn't available.
static func _autoInstantiate() -> (any ModuleAssembly)? { | ||
if let autoInit = self as? any AutoInitModuleAssembly.Type { | ||
return autoInit.init() | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static func _autoInstantiate() -> (any ModuleAssembly)? { | |
if let autoInit = self as? any AutoInitModuleAssembly.Type { | |
return autoInit.init() | |
} | |
return nil | |
static func _autoInstantiate() -> (any ModuleAssembly)? { | |
return nil |
Should we remove the as?
check here and always return nil
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or alternately remove the default extension implementation entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I take out the default implementation then I'll have to add it manually for any test cases where it's not being autogenerated.
let isAutoInit: Bool | ||
if config.assemblyType == .abstractAssembly { | ||
accessorBlock = AccessorBlockSyntax( | ||
accessors: .getter(.init(stringLiteral: "[.autoInit, .abstract]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this case covered in the unit tests currently, mind adding a test case for it?
7307774
to
ad7da66
Compare
ad7da66
to
8c24c71
Compare
This removes the need for some casts like
if ref.type is any AbstractAssembly.Type
which it turns out have a heavy performance penalty in large apps.This makes the code a little bit more complex but for a large app saves ~100ms in startup time.