Skip to content

[android][ime] Backspace/Delete becomes visibly slow per character after editing text in OpenLess fields #1527

Backlog

Description

@HKLHaoBin

Summary

在 Android 上使用 OpenLess IME 时,用户报告:在 OpenLess 自己的词典/类似文本输入框中输入内容后,点击 Backspace(或 Delete)会出现明显的逐字符卡顿;每删一个字符都要等待一段时间。用户尚未确认是否所有 OpenLess 输入框、所有输入模式或外部应用都复现。

本报告不把“词典”当作已确认根因:用户只知道问题是在编辑这类文本后出现,具体触发操作和平台细节仍需补齐。

Environment and supplied log

  • 平台:从 supplied log 首行 OpenLess mobile 启动 推断为 Android/mobile;确切设备、Android 版本、APK build 尚未知。
  • 日志时间:2026-12-01 12:39:45Z–14:32:45Z。
  • 日志大小/行数:8,417,407 bytes / 35,336 lines。
  • 日志包含 89 个 capture/session,32,415 行重复的 [OpenLessDbg58c22b] 状态通知警告。
  • 日志中没有 Backspace、Delete、keydown、keyup、vocab、dictionary、词典 或输入框耗时记录,因此它不能直接证明删除卡顿或定位根因。原始日志未上传,避免公开可能包含的个人内容。

Source-level leads from current upstream beta

调查固定在上游 beta SHA 10d8b533b4832d20f7354f60c46b7fdf3b4c9e95。

Android Rime path

The recent Android Rime migration (#1455, merged on December 1, 2026 at 04:14:41 UTC) is a plausible regression window. Its PR description explicitly left Android APK/Kotlin/real-device interaction validation pending.

In the current beta:

  • Pinyin-mode Backspace enters RimePinyinController.backspace() through OpenLessImeService.englishDeleteBackward():
    /** Backspace on the English keyboard: same field edit as everywhere else, plus keeping englishComposingWord (and therefore the candidate bar) in sync. In Pinyin mode, deletes from the (never-committed) encoding instead — falls back to the normal field edit only once the encoding is already empty (plan 3.3: "编码为空时 Backspace 恢复现有普通删除"). */
    private fun englishDeleteBackward() {
    if (latinInputMode == LatinInputMode.PINYIN) {
    rimePinyinController.backspace({ renderPinyinCandidates(it) }, {
    rimePinyinController.resetAssociationContext()
    deleteBackward()
    })
    return
    }
    clearEnglishAutoText()
    deleteBackward()
    if (englishComposingWord.isNotEmpty()) {
    englishComposingWord.deleteCharAt(englishComposingWord.length - 1)
    }
    updateEnglishCandidates()
  • Each request is queued on the single shared RimeTaskQueue and may perform native state, key=65288, candidates, and main-thread delivery:
    private fun submit(operation: String, argument: String, update: (List<String>) -> Unit, emptyAction: (() -> Unit)? = null) {
    val epoch = generation
    val revision = ++requestId
    if (!OpenLessRime.isReady && operation != "state") {
    statusHint = "词库初始化中…"
    main.post {
    if (epoch == generation && revision == requestId && !OpenLessRime.isReady) update(candidates)
    }
    }
    worker.execute {
    try {
    if (epoch != generation) return@execute
    OpenLessRime.initialize(context)
    // A dictionary import/export or a fuzzy-pinyin redeploy closed every native session.
    if (session.isNotEmpty() && sessionGeneration != OpenLessRime.sessionGeneration) {
    // A failed editor write still belongs to this editor even if
    // maintenance closed the native session before its retry.
    session = ""
    }
    if (session.isEmpty()) {
    sessionGeneration = OpenLessRime.sessionGeneration
    session = OpenLessRime.request("create", "", if (learning) "learning" else "private").getString("session")
    }
    if (pending.isNotEmpty()) {
    check(deliver(pending, epoch)) { "Editor write failed" }
    OpenLessRime.request("ack", session); pending = ""
    }
    if (pendingLiteral.isNotEmpty()) {
    check(deliver(pendingLiteral, epoch)) { "Editor write failed" }
    pendingLiteral = ""
    }
    // Inspect the native composition on the worker, after all earlier keys.
    // UI snapshots may lag behind fast typing or an in-flight commit.
    var state = OpenLessRime.request("state", session)
    val composing = state.optString("input").isNotEmpty()
    val nativeOperation = when (operation) {
    "backspace", "space", "confirmFirst" -> if (composing) "key" else "state"
    "literal" -> if (argument == "'" && composing) "key" else "confirm"
    "commitRaw" -> if (composing) "clear" else "state"
    else -> operation
    }
    val rawBeforeClear = if (operation == "commitRaw" && composing) state.optString("input") else ""
    val nativeArgument = when (operation) {
    "backspace" -> "65288"
    "space", "confirmFirst" -> "32"
    "literal" -> if (argument == "'" && composing) "39" else argument
    "commitRaw" -> ""
    else -> argument
    }
    if (!composing && operation in listOf("backspace", "space", "confirmFirst", "commitRaw")) {
    if (operation == "space") check(deliver(" ", epoch)) { "Editor write failed" }
    else check(onEditor(epoch) { emptyAction?.invoke(); true }) { "Editor unavailable" }
    } else {
    state = OpenLessRime.request(nativeOperation, session, nativeArgument)
    }
    if (operation == "literal" && nativeOperation == "confirm") pendingLiteral = argument
    if (rawBeforeClear.isNotEmpty()) pendingLiteral = rawBeforeClear
    pending = state.optString("commit")
    if (pending.isNotEmpty()) {
    check(deliver(pending, epoch)) { "Editor write failed" }
    state = OpenLessRime.request("ack", session); pending = ""
    }
    if (pendingLiteral.isNotEmpty()) {
    check(deliver(pendingLiteral, epoch)) { "Editor write failed" }
    pendingLiteral = ""
    }
    if (epoch != generation || revision != requestId) return@execute
    state = OpenLessRime.request("candidates", session)
    val input = state.optString("input")
    val preedit = state.optString("preedit").ifEmpty { input }
    val rows = state.optJSONArray("candidates")
    val result = if (rows == null) emptyList() else (0 until rows.length()).map { rows.getString(it) }
    val contextForPrediction = predictionContext
    val ranked = if (input.isNotEmpty() && learning &&
    OpenLessAndroidPreferences.strokeAssociationEnabled(context)) {
    RimePrediction.rank(result, contextForPrediction)
    } else result
    main.post {
    if (epoch != generation || revision != requestId) return@post
    val displayed = if (predictionContext == contextForPrediction) ranked else result
    statusHint = null
    // Keep the native order for selection indices; only reorder the visible list.
    encoding = input; preeditText = preedit; candidates = result; cloudChoices = emptySet()
    candidateRevision = state.optLong("revision"); update(displayed)
    scheduleCloud(input, displayed, epoch, revision, update)
  • The queue is shared by input/editor delivery and session-closing maintenance:
    /** Input (including editor delivery and ack) and session-closing maintenance share one queue. */
    internal object RimeTaskQueue {
    @Volatile private var workerThread: Thread? = null
    val executor = Executors.newSingleThreadExecutor { task ->
    Thread(task, "openless-rime").apply {
    isDaemon = true
    workerThread = this
    }
    }
    /** Maintenance callers are off the main thread; nested calls on this queue run directly. */
    fun <T> run(task: () -> T): T {
    if (Thread.currentThread() === workerThread) return task()
    return try {
    executor.submit(Callable { task() }).get()
    } catch (error: InterruptedException) {
  • Rime user-dictionary import and fuzzy-pinyin redeploy also use that queue:
    /** Writes the pinyin user dictionary snapshot to [target]; false when nothing has been learned yet. Off the main thread. */
    fun exportUserDictionary(context: Context, target: File): Boolean = RimeTaskQueue.run {
    initialize(context)
    closingSessions("user_dict_export", target.absolutePath).optBoolean("exported")
    }
    /** Validates and merges learned entries only; imported deletion markers cannot remove local words. Off the main thread. */
    fun importUserDictionary(context: Context, source: File) = RimeTaskQueue.run {
    val snapshot = RimeUserDictionaryFile.forImport(source.readText())
    val normalized = File.createTempFile("pinyin-import-", ".userdb.txt", context.cacheDir)
    try {
    normalized.writeText(snapshot)
    initialize(context)
    closingSessions("user_dict_import", normalized.absolutePath)
    Unit
    } finally { normalized.delete() }
    }
    /** Rewrites both pinyin schemas' patches for [groups] and redeploys them. Off the main thread. */
    fun applyFuzzyPinyin(context: Context, groups: Set<String>) = RimeTaskQueue.run {
    initialize(context)
    val patch = RimeFuzzyPinyin.customYaml(groups)
    for (schema in listOf("openless_pinyin_learning", "openless_pinyin_private")) {
    val file = File(context.filesDir, "rime-user/$schema.custom.yaml")
    if (patch == null) file.delete() else file.writeText(patch)
    }
    closingSessions("redeploy", "")
    Unit
  • English-mode Backspace re-queries English candidates after every deletion:
    /**
    * Re-queries EnglishCandidateProvider for the current englishComposingWord
    * prefix (or clears the bar if suggestions are off / nothing is being
    * typed) — called after every letter, backspace, and word boundary.
    * englishCandidateQueryEpoch discards a stale async result that comes
    * back after a faster subsequent keystroke already moved the prefix on.
    */
    private fun updateEnglishCandidates() {
    val epoch = ++englishCandidateQueryEpoch
    if (typingPanel == null) return
    if (!personalizedLearningAllowed() || !englishSuggestionsEnabled()) {
    renderEnglishCandidates(emptyList())
    return
    }
    val prefix = englishComposingWord.toString()
    if (prefix.isEmpty()) {
    renderEnglishCandidates(emptyList())
    return
    }
    englishCandidateProvider.queryTopN(prefix, ENGLISH_CANDIDATE_QUERY_LIMIT) { results ->
    if (epoch == englishCandidateQueryEpoch) renderEnglishCandidates(results)
    }

This is a candidate mechanism, not a confirmed root cause. The supplied log lacks the timings needed to distinguish queue wait, native Rime latency, candidate callback backlog, InputConnection latency, and target WebView rendering.

Global Dictionary action

The clipboard Dictionary action calls the Android native bridge asynchronously and then refreshes the panel:

  • private fun renderClipboardPanel() {
    val panel = clipboardPanel ?: return
    val epoch = sessionEpoch
    val all = OpenLessClipboardHistory.load(this).distinctBy { it.text }
    val vocabulary = if (clipboardHistoryMode && isBackendReady()) {
    runCatching {
    val array = org.json.JSONArray(OpenLessNative.nativeVocabularyPhrases())
    (0 until array.length()).mapTo(mutableSetOf()) { array.getString(it) }
    }.getOrDefault(emptySet())
    } else emptySet()
    fun item(entry: ClipboardEntry) = ImeClipboardPanel.Item(
    text = entry.text,
    favorite = entry.favorite,
    inDictionary = entry.text in vocabulary,
    select = {
    if (clipboardActionCurrent(epoch)) pasteClipboardHistory(entry.text)
    },
    toggleFavorite = {
    if (clipboardActionCurrent(epoch)) {
    OpenLessClipboardHistory.toggleFavorite(this, entry.text)
    renderClipboardPanel()
    }
    },
    remove = {
    if (clipboardActionCurrent(epoch)) {
    OpenLessClipboardHistory.delete(this, entry.text)
    renderClipboardPanel()
    }
    },
    toggleDictionary = {
    if (clipboardActionCurrent(epoch)) toggleClipboardDictionary(entry.text, entry.text in vocabulary)
    },
    )
    panel.render(
    epoch, clipboardHistoryMode, clipboardSelectionMode, clipboardHistoryCategory.name,
    OpenLessClipboardHistory.filter(all, clipboardHistoryCategory).map(::item),
    all.take(3).map(::item),
    )
    panel.setBlocked(dictationEditingLocked())
    }
    private fun pasteClipboardHistory(text: String) {
    if (currentInputConnection?.commitText(text, 1) == true) {
    OpenLessClipboardHistory.recordCopy(this, text)
    clipboardHistoryMode = false
    renderClipboardPanel()
    } else {
    OpenLessNativeNotice.makeText(this, ui("输入连接已失效,未粘贴", "Editor unavailable; nothing pasted"), Toast.LENGTH_SHORT).show()
    }
    }
    private fun toggleClipboardDictionary(text: String, present: Boolean) {
    if (!isBackendReady()) {
    ensureBackendReady()
    OpenLessNativeNotice.makeText(this, ui("词典服务正在准备,请稍后重试", "Dictionary is preparing; please retry"), Toast.LENGTH_SHORT).show()
    return
    }
    runCatching {
    if (present) OpenLessNative.nativeRemoveVocabularyWord(text) else OpenLessNative.nativeAddVocabularyWord(text)
    }.onSuccess { renderClipboardPanel() }.onFailure {
    OpenLessNativeNotice.makeText(this, ui("词典操作失败,请重试", "Dictionary operation failed; please retry"), Toast.LENGTH_SHORT).show()
    }
    }
  • /// Records a spoken correction as a global Dictionary entry instead of a
    /// CorrectionRule — the IME's "edit result"/clipboard-correction flows used
    /// to auto-generate a pattern->replacement rule from every edit; that's now
    /// hand-maintained only (desktop's Corrections settings page), and these
    /// flows just remember the corrected word/phrase itself, the same
    /// mechanism `add_vocab` (commands/dictionary.rs) exposes to the desktop
    /// Dictionary UI. `add_vocabulary_if_absent` skips silently if the phrase
    /// is already known, so repeatedly correcting the same word never piles up
    /// duplicate entries.
    fn spawn_add_vocabulary_word(phrase: String) {
    let Some(backend) = CORE_BACKEND.get().cloned() else {
    log::warn!("[android-native] core backend unavailable");
    return;
    };
    if phrase.trim().is_empty() {
    return;
    }
    tauri::async_runtime::spawn(async move {
    if let Err(error) = backend.add_vocabulary_if_absent(phrase, None) {
    log::warn!("[android-native] add_vocabulary_if_absent failed: {error}");
    }
    });

The source does not yet prove that the global Dictionary write itself blocks the Rime queue; the report should ask maintainers to distinguish that action from Rime user-dictionary import/redeploy and from ordinary text-field editing.

Reproduction requested

  1. Record APK version/build, device, Android version, input mode (English/Pinyin/Stroke), and whether Rime user-dictionary import/redeploy was used.
  2. Reproduce in the OpenLess dictionary-like field, another OpenLess field, and an external app with the same text.
  3. Compare: no Dictionary action; after Add to Dictionary; after Rime user-dictionary import/redeploy; after IME restart.
  4. Capture per-key timing for Backspace from action dispatch to visible text change.
  5. Add bounded timing probes for queue wait, Rime state/key/candidates, InputConnection, and main-thread candidate rendering, without recording text.

Acceptance criteria

  • A Dictionary or Rime maintenance operation cannot indefinitely delay ordinary Backspace.
  • Stale per-key Rime requests do not accumulate and consume main-thread work after the user has already deleted further characters.
  • Ordinary deletion remains correct for Pinyin composition, English candidate mode, selections, and Unicode/code points.
  • The same reproduction is verified on the actual Android device/build, not only by source inspection.

Duplicate check

Searches covered English/Chinese terms for backspace, delete, input lag, keyboard freeze, typing, Rime, Pinyin, dictionary, and 卡顿. Existing #1526 is an Android backspace gesture feature request, not this latency report.

Activity

  1. HKLHaoBin commented on Dec 2, 2026

    @HKLHaoBin
    CollaboratorAuthor

    Android diagnostic artifact is ready for Issue #1527 testing.

    Testing scope:

    1. Download the artifact from the Actions artifact page; GitHub login may be required.
    2. Install the arm64 APK on a test Android device.
    3. Reproduce the backspace-lag cases in both Pinyin and English paths, first with the existing key_debug_features_enabled preference off, then with it enabled.
    4. For diagnostic collection, capture only the single-line records marked [DEBUG-ISSUE-1527]; do not include typed text, candidate text, host package names, paths, credentials, or raw exceptions.
    5. Please report which path was tested, whether the lag occurred, and attach the privacy-filtered diagnostic lines if available.

    This is an observation-only diagnostic build. It does not claim that the runtime root cause is confirmed or that the issue is fixed. CI and the desktop workflow are still running separately; this Android artifact is the early platform milestone.

  2. HKLHaoBin commented on Dec 3, 2026

    @HKLHaoBin
    CollaboratorAuthor

    Updated Android diagnostic artifact for Issue #1527 is ready from the reviewed candidate.

    This artifact includes the Android instrumentation-compatibility repair and the completed diagnostic lifecycle fixes. It supersedes the earlier APK from commit 1ce591c7a427a727fa40bd3a2a41fd1541b78635.

    Testing scope remains observation-only:

    1. Download the artifact from the Actions artifact page; GitHub login may be required.
    2. Install the arm64 APK on a test Android device.
    3. Reproduce the backspace-lag cases in both Pinyin and English paths, first with key_debug_features_enabled off, then with it enabled.
    4. Capture only single-line records marked [DEBUG-ISSUE-1527]; do not include typed text, candidate text, host package names, paths, credentials, or raw exceptions.
    5. Report the path tested, whether lag occurred, and attach privacy-filtered diagnostic lines if available.

    CI and the Tauri desktop workflow for this same commit are still running separately. No root cause or product fix is claimed yet.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions