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

Optimize PackageInfoService #1136

Merged
merged 10 commits into from
Sep 27, 2017
Merged

Conversation

ben-clayton
Copy link
Contributor

@ben-clayton ben-clayton commented Sep 26, 2017

Reduces package info with icons from ~17 seconds down to 2.5s (warm cache), 8s (cold cache) on my test device.

Fixes: #1000

Collections.sort(sorted, new Comparator<Counter>() {
@Override
public int compare(Counter a, Counter b) {
if (a.time < b.time) { return 1; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return Float.compare(b.time, a.time);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

private final Counter counter;

private Scope(Counter counter) {
this.start = System.currentTimeMillis();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably should use System.nanoTime, since System.currentTimeMillis may not be monotonic and has very loose guarantees.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

} else {
return mMap.get(pngBase64);
}
} finally {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are undoing most of this change in the next commit. Maybe squash the 'add try, remove try' parts?


/**
* Lookups the value from the cache using the given key. If the cache does not contain the value
* then the {@link Builder} will be used to create the value.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment that this is not thread safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made thread safe instead.

private FileCache() {
}

static <K, V> Cache<K, V> create(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this not public?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}

public V scopedBuild(K key) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

for (int n; (n = is.read(buf)) != -1; ) {
os.write(buf, 0, n);
}
os.flush();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove. It does nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@ben-clayton ben-clayton merged commit 2d5daaa into google:master Sep 27, 2017
@ben-clayton ben-clayton deleted the opt-pkginfo branch September 27, 2017 14:38
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.

2 participants