Skip to content

Conversation

@ujohnny
Copy link
Collaborator

@ujohnny ujohnny commented Dec 1, 2025

getSourceToTargetMap might be called under read action and it's
a quite heavy operation. we can bring cancellation checks into it,
but

a. it might be called under non-cancellable read action
b. it might take tens of seconds to compute, so no readaction
can survive this long

so if we're called under readaction, we just return null and schedule
background computation, and hope we will be called some time later

@github-actions github-actions bot added product: CLion CLion plugin product: IntelliJ IntelliJ plugin product: GoLand GoLand plugin awaiting-review Awaiting review from Bazel team on PRs labels Dec 1, 2025
@ujohnny ujohnny force-pushed the enovozhilov/prevent-freeze branch 4 times, most recently from 39c6036 to de678b5 Compare December 1, 2025 22:08
getSourceToTargetMap might be called under read action and it's
a quite heavy operation. we can bring cancellation checks into it,
but

a. it might be called under non-cancellable read action
b. it might take tens of seconds to compute, so no readaction
can survive this long

so if we're called under readaction, we just return null and schedule
background computation, and hope we will be called some time later.
but we expect to be called from ProjectTargetManagerImpl on the
background thread, so we can build map, but in case we're invoked
from someone else before, background computation will prevent the
freeze
@ujohnny ujohnny force-pushed the enovozhilov/prevent-freeze branch from de678b5 to 89506c6 Compare December 1, 2025 22:20
Copy link
Collaborator

@LeFrosch LeFrosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good just a bunch of nit picks. And I changed my mind, this is probably more reliable then my Deferred idea.

Comment on lines +61 to +63
scope.launch {
get(key, computable)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this swallow exceptions?

@@ -0,0 +1,55 @@
package com.google.idea.blaze.base.sync
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copy right

Comment on lines +17 to +20
sealed class TryLockResult<out T> {
data class Acquired<T>(val value: T) : TryLockResult<T>()
data object NotAcquired : TryLockResult<Nothing>()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this basically an Optional?

/** Computes a cache on the project data. */
@Service(Service.Level.PROJECT)
class SyncCache(private val project: Project, private val scope: CoroutineScope) {
/** Computes a value based on the sync project data. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indentation of 4 spaces instead of 2

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting as I use https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml, but it does not have kotlin settings, moreover there's no kotlin styleguide in this repo at all

fun compute(project: Project, projectData: BlazeProjectData): T?
}

private data class Data(val cache: MutableMap<Any, Any?>)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of wrapping the Map in the data class?

* Encapsulates the data into [hidden] and allows retriable access to it
* with cancellation checks
*/
class LockCriticalSection<Hidden : Any>(private val hidden: Hidden) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only use this class for the SyncCache and it's only ever instantiated for a HashMap, we could drop some of the generic parameters in favor of specialization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review Awaiting review from Bazel team on PRs product: CLion CLion plugin product: GoLand GoLand plugin product: IntelliJ IntelliJ plugin

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

4 participants