Android: `EditorService` does disk and SSL work on the caller's thread

Aperta
#869 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, kotlin

Direzione di ricerca

Start with EditorService (create, prepare, fetchAssetBundleCount, cleanup, purge) and EditorDependenciesSerializer (writeToDisk, readFromDisk), then trace the disk and SSL calls into EditorAssetsLibrary.readAssetBundles and the EditorHTTPClient setup. Begin with the first proposed step: move the cleanup() call inside prepare onto Dispatchers.IO. Done means prepare is safe on the main thread, and every other listed API either runs off the caller's thread or documents that it blocks. The API shape is still undecided, so confirm the approach with maintainers before changing signatures.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

[Type] Code Quality Android

EditorService and EditorDependenciesSerializer do disk and SSL work on whichever thread calls them, so a host that calls them on the main thread gets slow frames and StrictMode violations. Nothing in the API or its KDoc says to avoid this.

No shipping host is affected today. WordPress-Android calls EditorService.create and prepare from a background dispatcher in GutenbergEditorPreloader. It also doesn't use the serializer or the other calls below, and its StrictMode setup is commented out. The cost is to the next host, and to the demo app, which wraps every call by hand (#489).

This is separate from #848, which covers the work inside GutenbergView that a host can't move. These are calls the host makes itself, so they can move.

What happens

API Blocking work Why it matters
EditorService.create EditorHTTPClient SSL setup, Paths.*Root, getSharedPreferences, EditorURLCache and EditorAssetsLibrary init Not suspend, so nothing suggests it blocks
EditorService.prepare Periodic cleanup() → EditorAssetsLibrary.readAssetBundles It's suspend, so callers will expect it to be safe on the main thread
EditorService.fetchAssetBundleCount EditorAssetsLibrary.readAssetBundles Not suspend
EditorService.cleanup, purge Deletes files Not suspend
EditorDependenciesSerializer.writeToDisk, readFromDisk Reads or writes the dependencies file Not suspend

Possible fix

  1. prepare: run cleanup() on Dispatchers.IO inside the library. This has no API change and should come first.
  2. The rest: make them suspend and move to Dispatchers.IO inside the library. This is a breaking change for hosts, though a small one, since WordPress-Android already calls create from a coroutine.
  3. If 2 is too disruptive: document the blocking calls in KDoc instead.

Done when

  • prepare is safe to call from the main thread.
  • Each API above either moves its work off the caller's thread or says in its KDoc that it blocks.
  • The demo's withContext(Dispatchers.IO) wrappers around these calls are removed where they're no longer needed.

Related issues

  • #848 — editor load work inside GutenbergView.
  • #489 — the demo app wrappers, and the review that raised this.
Lingua principale
JavaScript
Stelle
29
Fork
6
Merge medio
2g 1h
PR unite (30g)
76

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wordpress-mobile/GutenbergKit

Tutte le issue di wordpress-mobile/GutenbergKit

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.