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

Avoid JSON deserialization in common trivial cases #11251

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public class FileDataStorageManager {
private static final String EXCEPTION_MSG = "Exception in batch of operations ";

public static final int ROOT_PARENT_ID = 0;
public static final String NULL_STRING = "null";
private static final String JSON_NULL_STRING = "null";
private static final String JSON_EMPTY_ARRAY = "[]";

private final ContentResolver contentResolver;
private final ContentProviderClient contentProviderClient;
Expand Down Expand Up @@ -931,7 +932,10 @@ private OCFile createFileInstance(FileEntity fileEntity) {
ocFile.setLockToken(fileEntity.getLockToken());

String sharees = fileEntity.getSharees();
if (sharees == null || NULL_STRING.equals(sharees) || sharees.isEmpty()) {
// Surprisingly JSON deserialization causes significant overhead.
// Avoid it in common, trivial cases (null/empty).
if (sharees == null || sharees.isEmpty() ||
JSON_NULL_STRING.equals(sharees) || JSON_EMPTY_ARRAY.equals(sharees)) {
ocFile.setSharees(new ArrayList<>());
} else {
try {
Expand All @@ -944,9 +948,13 @@ private OCFile createFileInstance(FileEntity fileEntity) {
}

String metadataSize = fileEntity.getMetadataSize();
ImageDimension imageDimension = gson.fromJson(metadataSize, ImageDimension.class);
if (imageDimension != null) {
ocFile.setImageDimension(imageDimension);
// Surprisingly JSON deserialization causes significant overhead.
// Avoid it in common, trivial cases (null/empty).
if (!(metadataSize == null || metadataSize.isEmpty() || JSON_NULL_STRING.equals(metadataSize))) {
ImageDimension imageDimension = gson.fromJson(metadataSize, ImageDimension.class);
if (imageDimension != null) {
ocFile.setImageDimension(imageDimension);
}
}

return ocFile;
Expand Down