Skip to content

Conversation

@MattSkala
Copy link
Contributor

Fixes #902

@google-oss-bot
Copy link
Contributor

Hi @MattSkala. Thanks for your PR.

I'm waiting for a firebase member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@var-const
Copy link
Contributor

@wilhuff If I'm reading the relevant code correctly, it uses ConcurrentHashMap, which is thread-safe, but also relies on reassigning the variable itself, which isn't. One alternative that comes to mind is creating the map non-lazily and clearing it instead of setting it to null. Let me know what you think.

/ok-to-test

@MattSkala
Copy link
Contributor Author

@var-const I agree making fieldValueCache non-null is a better solution, should I change it?

@wilhuff
Copy link
Contributor

wilhuff commented Oct 14, 2019

ConcurrentHashMap is pretty expensive and most users get the whole document contents rather than just an individual field. The fieldValueCache is lazily instantiated to avoid adding this overhead to every Document unconditionally. The cache exists at all because internally, when sorting results, we can access the same field multiple times. (The TODO in the code is really indicating that we should apply a Schwartzian transform before sorting at which point we can eliminate the cache altogether.)

This fix seems OK as is.

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.

LGTM

@wilhuff wilhuff merged commit e1fc161 into firebase:master Oct 14, 2019
wilhuff added a commit that referenced this pull request Oct 14, 2019
wilhuff added a commit that referenced this pull request Oct 14, 2019
@firebase firebase locked and limited conversation to collaborators Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DocumentSnapshot.get throws NullPointerException

5 participants