mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Disable transformer when super stressed
This commit is contained in:
parent
ecaf9df340
commit
21800d37e2
@ -381,6 +381,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
|
||||
override fun onStartInput(attribute: EditorInfo?, restarting: Boolean) {
|
||||
super.onStartInput(attribute, restarting)
|
||||
latinIMELegacy.onStartInput(attribute, restarting)
|
||||
languageModelFacilitator.onStartInput()
|
||||
}
|
||||
|
||||
override fun onStartInputView(info: EditorInfo?, restarting: Boolean) {
|
||||
|
@ -133,6 +133,9 @@ public class LanguageModelFacilitator(
|
||||
public fun hasPendingUpdate(): Boolean =
|
||||
computationSemaphore.availablePermits == 0
|
||||
|
||||
|
||||
private var numConsecutiveTimeouts = 0
|
||||
private var transformerDisabled = false
|
||||
public fun blockUntilComplete() {
|
||||
runBlocking {
|
||||
try {
|
||||
@ -145,8 +148,14 @@ public class LanguageModelFacilitator(
|
||||
|
||||
}
|
||||
}
|
||||
numConsecutiveTimeouts = 0
|
||||
} catch(e: TimeoutCancellationException) {
|
||||
Log.d("LanguageModelFacilitator", "Failed to complete prediction within 1000ms!")
|
||||
numConsecutiveTimeouts += 1
|
||||
if(numConsecutiveTimeouts > 5) {
|
||||
transformerDisabled = true
|
||||
Log.w("LanguageModelFacilitator", "Temporarily disabling transformer due to continuous timeouts")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,6 +180,8 @@ public class LanguageModelFacilitator(
|
||||
}
|
||||
|
||||
private suspend fun runLanguageModel(values: PredictionInputValues): ArrayList<SuggestedWordInfo>? {
|
||||
if(transformerDisabled) return null
|
||||
|
||||
val locale = dictionaryFacilitator.locale ?: return null
|
||||
if (languageModel == null || (languageModel?.locale?.language != locale.language)) {
|
||||
Log.d(
|
||||
@ -602,4 +613,9 @@ public class LanguageModelFacilitator(
|
||||
assert(historyLog.isEmpty())
|
||||
loadHistoryLogBackup(context, historyLog)
|
||||
}
|
||||
|
||||
public fun onStartInput() {
|
||||
transformerDisabled = false
|
||||
numConsecutiveTimeouts = 0
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user