Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SAF performance and defer custom filename template processing to the end of the call #257

Merged
merged 2 commits into from
Feb 24, 2023

Conversation

chenxiaolong
Copy link
Owner

As encountered in #252, some devices have a horrendous SAF implementation that takes upwards of 8 seconds just to check for the existence of bcr.properties in the output directory. The main cause of the delay is that the DocumentFile.findFile() implementation is very inefficient and performs a separate query to the document provider for each child in the directory. The first commit addresses this by reimplementing the method to use a single query.

However, even with the optimized query, it still takes >500ms on some devices, so the second commit updates RecorderThread to defer custom filename template processing until the end of the call.

To illustrate the absurdity of this slowness, when using native Files with the default output directory (no-SAF) on the same device, the same set of operations takes 2ms.

Fixes: #252

On some devices, Android's Storage Access Framework is astoundingly
slow. This is due to the listFiles() and findFile() implementations
performing separate ContentResolver queries for every child item in the
directory. This commit introduces extension methods for DocumentFile
that perform these operations using only a single query.

Issue: #252

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
Simply checking for the existence of bcr.properties leads to a >500ms
delay on some devices due to the slowness of SAF.

Issue: #252

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
@chenxiaolong chenxiaolong self-assigned this Feb 24, 2023
@chenxiaolong chenxiaolong merged commit a831109 into master Feb 24, 2023
@chenxiaolong chenxiaolong deleted the issue252 branch February 24, 2023 20:00
chenxiaolong added a commit that referenced this pull request Feb 24, 2023
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
chenxiaolong added a commit that referenced this pull request Mar 1, 2023
We call it via reflection in our faster DocumentFile extensions and the
first parameter was being optimized out in release builds because it is
always null in the usages that R8 is able to analyze.

Related-to: #257
Fixes: #260

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

First nearly 7-8 seconds not recorded
1 participant