Skip to content

Android: Filesystem operations run on the UI thread (Dispatchers.Main instead of Dispatchers.IO) #57

@thomasjahoda

Description

@thomasjahoda

Bug Report

On Android this plugin schedules all IO operations on the UI thread.
I would consider this issue pretty critical as it causes really noticable lags when the plugin has ongoing calls. For months I didn't know that this may be the main cause of lags in my app (my app saves data in the background very frequently).

Capacitor Version

  @capacitor/cli: 7.4.3
  @capacitor/android: 7.4.3
  @capacitor/core: 7.4.3
  @capacitor/ios: 7.4.3

  @capacitor/filesystem: 7.1.4

Platform(s)

Android only.

Current Behavior

Native IO operations run on the UI thread.

Expected Behavior

Native IO operations run via some IO thread pool.
Just replace Dispatchers.Main with Dispatchers.IO. I patched it for my project currently and it seems to have fixed the issues I had with it.

Code Reproduction

No repro provided and necessary if you just look at the code.
It should be Dispatchers.IO instead of Dispatchers.Main. Main is the UI scope, as can be seen in the docs of MainCoroutineDispatcher or probably lots of other documentation:

Base class for special CoroutineDispatcher which is confined to application "Main" or "UI" thread and used for any UI-based activities. Instance of MainDispatcher can be obtained by Dispatchers.Main.
Platform may or may not provide instance of MainDispatcher, see documentation to Dispatchers.Main

If you really need a reproduction example, I guess I can write some snippet to repeatedly append lots of data to a file.

Other Technical Details

Included in 'Code Reproduction'.

Additional Context

Included in 'Code Reproduction'.

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