ionic-team / ionic-team/capacitor-filesystem

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

Open
#57 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6
Forks
15
Avg merge
14m
Merged PRs (30d)
1

Description

## 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](https://github.com/ionic-team/capacitor-filesystem/blob/main/packages/capacitor-plugin/android/src/main/kotlin/com/capacitorjs/plugins/filesystem/FilesystemPlugin.kt#L57).
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'.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.