-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add smol caching & a utility method #1239
Conversation
@@ -58,6 +58,21 @@ public class WorkflowIdentifier internal constructor( | |||
|
|||
private val proxiedIdentifiers = generateSequence(this) { it.proxiedIdentifier } | |||
|
|||
private val cachedToString by lazy { |
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.
FYI: Each by lazy
allocates an additional private object to store the property delegate. If we don't need multi-thread synchronization, it's cheaper to just use a nullable backing property and initialize it yourself. Usually matters more for framework code, so we might want to avoid by lazy
here.
E.g.
private var _cachedToString: String?
private val cachedToString: String
get() = _cachedToString ?: calculateToString().also { _cachedToString = it }
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.
Did that but made cachedToString volatile because I'm not 100% this is actually single threaded. volatile is still better than using synchronization primitives as there's no locking, and the downside is that we might sometimes race init and compute it twice then set it twice to the same value, which is ok.
See build failure - we run in |
* Either a [KClass] or [KType] representing the "real" type that this identifier | ||
* identifies – i.e. which is not an [ImpostorWorkflow]. | ||
*/ | ||
public val realIdentifierType by lazy { |
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 what needs an explicit type declared.
37d902a
to
a14b08d
Compare
I was surprised that the IDE was fine with it. |
574eb29
to
4668c23
Compare
To avoid the conflict, renamed the field to |
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
No description provided.