Move note language computation off the main thread

NLLanguageRecognizer.processString() is an expensive NLP operation that
was moved to @MainActor in 5058fb33, causing UI jank when scrolling.

This moves language detection back to the async preload path where it
runs off the main thread. get_preload_plan is synchronous again and
defers language computation to preload_event. Translations still happen
on the first preload pass since preload_event now checks .havent_tried
directly rather than relying on the load_translations flag from the plan.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
William Casarin
2026-02-10 10:16:25 -08:00
parent 2d5460b654
commit be6b0e2702
3 changed files with 24 additions and 39 deletions

View File

@@ -568,8 +568,8 @@ extension NdbNote {
return thread_reply() != nil
}
@MainActor
func note_language(ndb: Ndb, _ keypair: Keypair) -> String? {
func note_language(_ keypair: Keypair) -> String? {
assert(!Thread.isMainThread, "This function must not be run on the main thread.")
// Rely on Apple's NLLanguageRecognizer to tell us which language it thinks the note is in
// and filter on only the text portions of the content as URLs and hashtags confuse the language recognizer.