Skip to content

LocalStore uses a SparseArray to track target ids, not a set #65

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

Merged
merged 3 commits into from
Oct 9, 2018

Conversation

gsoltis
Copy link
Contributor

@gsoltis gsoltis commented Oct 8, 2018

No functional changes, just switches Set -> SparseArray for LRU stuff since LocalStore already uses a SparseArray to track active targets.

@gsoltis
Copy link
Contributor Author

gsoltis commented Oct 8, 2018

Eh, hang on. I apparently only ran a subset of tests locally :(

@gsoltis gsoltis assigned gsoltis and unassigned schmidt-sebastian Oct 8, 2018
@gsoltis gsoltis assigned schmidt-sebastian and unassigned gsoltis Oct 8, 2018
@gsoltis
Copy link
Contributor Author

gsoltis commented Oct 8, 2018

Ok, fixed it. It was android stuff.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

We have customers doing thousands of listens (essentially all document lookups) and the SparseArray docs indicate performance is only 50% worse with "hundreds" of entries and that it shouldn't be used for large collections.

I'm not morally opposed to this, but how much worse is it for these worse-case customers?

@gsoltis
Copy link
Contributor Author

gsoltis commented Oct 8, 2018

I'm not adding the SparseArray, I'm making use of the one that's already there in LocalStore. I don't have an opinion on whether or not it should be that or a Map, other than a slight preference for non-Android-specific stuff.

@gsoltis
Copy link
Contributor Author

gsoltis commented Oct 8, 2018

/test connected-check

@gsoltis
Copy link
Contributor Author

gsoltis commented Oct 8, 2018

/test smoke-tests-release

@gsoltis
Copy link
Contributor Author

gsoltis commented Oct 8, 2018

/test connected-check

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

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

I am mostly fine with this. I have questions regarding the use of the wildcard.

Furthermore, at least in the tests you are no longer storing "activeTargetIds". I think you should rename a bunch of the variables/arguments.

@@ -115,13 +115,13 @@ public void removeQueryData(QueryData queryData) {
*
* @return the number of targets removed
*/
int removeQueries(long upperBound, Set<Integer> activeTargetIds) {
int removeQueries(long upperBound, SparseArray<?> activeTargetIds) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The code in this function indicates to me that we always need to accept a SparseArray. For any other sparse array, activeTargetIds.get(targetId) would return null. Can you explain to me why you chose the wildcard in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Er, why would any other SparseArray return null? The target ids are the keys, and SparseArray is required to use integer keys. It doesn't matter what the value is, we are only ever using the keys. Because we don't care about the value, the ? is appropriate. It indicates we will not make use of the value, which we don't.

Copy link
Contributor

Choose a reason for hiding this comment

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

As per our offline discussion, this is ok. It's just not the most obvious use of an array-like data structure to me. I wish it was possible to make the key-only nature more obvious (such as with a Map's keySet), but since that's not possible without a copy, this LGTM

@gsoltis gsoltis merged commit 5e3a516 into master Oct 9, 2018
@gsoltis gsoltis deleted the gsoltis/use_sparse_array branch October 9, 2018 16:26
@firebase firebase locked and limited conversation to collaborators Oct 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants