Fix problem where wrong autocorrection is used during stress

This commit is contained in:
Aleksandras Kostarevas 2024-04-29 21:10:30 -04:00
parent 21800d37e2
commit 740bd08e28
2 changed files with 13 additions and 6 deletions

View File

@ -1502,12 +1502,12 @@ public final class InputLogic {
}
}
private void ensureSuggestionStripCompleted(final SettingsValues settingsValues,
private boolean ensureSuggestionStripCompleted(final SettingsValues settingsValues,
final String separator, final LatinIMELegacy.UIHandler handler) {
LanguageModelFacilitator facilitator = handler.getLanguageModelFacilitator();
if(!facilitator.shouldPassThroughToLegacy()) {
if(facilitator.hasPendingUpdate()) {
facilitator.blockUntilComplete();
return facilitator.blockUntilComplete();
}
} else {
if (handler.hasPendingUpdateSuggestions()) {
@ -1523,6 +1523,8 @@ public final class InputLogic {
performUpdateSuggestionStripSync(settingsValues, SuggestedWords.INPUT_STYLE_TYPING);
}
}
return true;
}
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues,
@ -2177,7 +2179,8 @@ public final class InputLogic {
private void commitCurrentAutoCorrection(final SettingsValues settingsValues,
final String separator, final LatinIMELegacy.UIHandler handler) {
// Complete any pending suggestions query first
ensureSuggestionStripCompleted(settingsValues, separator, handler);
if(!ensureSuggestionStripCompleted(settingsValues, separator, handler)) return;
final SuggestedWordInfo autoCorrectionOrNull = mWordComposer.getAutoCorrectionOrNull();
final String typedWord = mWordComposer.getTypedWord();
final String stringToCommit = (autoCorrectionOrNull != null)

View File

@ -136,10 +136,10 @@ public class LanguageModelFacilitator(
private var numConsecutiveTimeouts = 0
private var transformerDisabled = false
public fun blockUntilComplete() {
public fun blockUntilComplete(): Boolean {
runBlocking {
try {
withTimeout(1000L) {
withTimeout(700L) {
computationSemaphore.acquire()
computationSemaphore.release()
try {
@ -150,14 +150,16 @@ public class LanguageModelFacilitator(
}
numConsecutiveTimeouts = 0
} catch(e: TimeoutCancellationException) {
Log.d("LanguageModelFacilitator", "Failed to complete prediction within 1000ms!")
Log.d("LanguageModelFacilitator", "Failed to complete prediction within the time!")
numConsecutiveTimeouts += 1
if(numConsecutiveTimeouts > 5) {
transformerDisabled = true
Log.w("LanguageModelFacilitator", "Temporarily disabling transformer due to continuous timeouts")
}
return@runBlocking false
}
}
return true
}
private fun getEmojiCandidate(word: String): SuggestedWordInfo? {
@ -232,6 +234,8 @@ public class LanguageModelFacilitator(
computationSemaphore.acquire()
inputLogic.mWordComposer.setAutoCorrection(null)
try {
var transformerWeight = context.getSetting(BinaryDictTransformerWeightSetting)