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

1.x Remove all instances of Atomic*FieldUpdater #3488

Merged
merged 1 commit into from
Nov 11, 2015

Conversation

markrietveld
Copy link

Replace them all with their respective Atomic* counterparts
For example AtomicLongFieldUpdater -> AtomicLong
Addresses #3459

@artem-zinnatullin
Copy link
Contributor

There is a reason for AtomicFieldUpdater + volatile value — lower memory consumption (cc @akarnokd), but personally, I'd like to switch to Atomic fields too to get rid of reflection in such hot code.

#3459 is Samsung's problem. Even though we see it in our apps (somebody told me that it's about 5% of Samsung devices of our users) I don't think that such platform specific bugs should be solved on library side.

@akarnokd
Copy link
Member

akarnokd commented Nov 3, 2015

As @artem-zinnatullin mentioned, field updaters were introduced to reduce number of allocations and runtime size of the library; especially for the Android platform.

Although field updaters have 1-5% overhead compared to Unsafe, the same overhead may manifest with Atomic instances due to the one level indirection, plus usually the surrounding logic forces a re-read of the AtomicXXX field all the time if not done with care.

See my other comments in the code.

@SuppressWarnings("rawtypes")
static final AtomicReferenceFieldUpdater<LatestObserverIterator, Notification> REFERENCE_UPDATER
= AtomicReferenceFieldUpdater.newUpdater(LatestObserverIterator.class, Notification.class, "value");
AtomicReference<Notification<? extends T>> value = new AtomicReference<Notification<? extends T>>();
Copy link
Member

Choose a reason for hiding this comment

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

final

davidmoten added a commit to davidmoten/rxjava-extras that referenced this pull request Nov 6, 2015
@markrietveld
Copy link
Author

I started a run on this branch now using ./gradlew benchmarks '-Pjmh=.*OperatorObserveOnPerf.*'. The ETA for that is in over 2 hours. Does that seem right?

@markrietveld
Copy link
Author

I ran JMH yesterday for this commit and the preceding one. The results are on my computer at home, and I'm at work now. I'll post them when I get back

@markrietveld
Copy link
Author

Here is the screenshot. The first result is from 51527b7, the second one is from after the changes in this pull request:
image

@akarnokd I'm not sure if I used the GUI right. I can't get it to use something as a baseline. I pasted the result from 51527b7 first, and then the result from this pull request. Do I need to do something else?

@akarnokd
Copy link
Member

Right click in a cell and you get a popup menu with options.

@akarnokd
Copy link
Member

Otherwise, no performance regression. 👍

@stealthcode
Copy link

👍

@@ -139,7 +135,8 @@ public void request(long n) {
* that there is always once who acts on each `tick`. Same concept as used in OperationObserveOn.
*/
void tick() {
if (WIP.getAndIncrement(this) == 0) {
AtomicLong localCounter = this.counter;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for having copy of final reference?

@artem-zinnatullin
Copy link
Contributor

👍, few nits. Looks like @akarnokd wants local copies of final references, but I don't, though I'm ok with having them — you can just fix @SuppressWarnings("unused").

@akarnokd can you please give a link or describe how local copy of final reference will help? I mean, JIT will ~100% won't make re-reads of final references until it detect change of the reference via reflection. Or I'm wrong?

@akarnokd
Copy link
Member

Keep the locals as I suggested. JIT re-reads them unfortunately. I read and experienced this myself with JCTools queries and range().

@artem-zinnatullin
Copy link
Contributor

That's sad. Okay, then just SuppressWarnings need to be fixed.

Netflix team: can we expect 1.0.16 soon? As mentioned in the original issue
this PR would prevent crashes in many apps.

On Wed, Nov 11, 2015, 11:24 David Karnok notifications@github.com wrote:

Keep the locals as I suggested. JIT re-reads them unfortunately. I read
and experienced this myself with JCTools queries and range().


Reply to this email directly or view it on GitHub
#3488 (comment).

@artem_zin

@markrietveld
Copy link
Author

@artem-zinnatullin I removed the erroneous annotations

@artem-zinnatullin
Copy link
Contributor

👍, thanks!

@akarnokd
Copy link
Member

Please squash this again.

Replace them all with their respective Atomic* counterparts
For example AtomicLongFieldUpdater -> AtomicLong
Addresses ReactiveX#3459
@markrietveld
Copy link
Author

Done

akarnokd added a commit that referenced this pull request Nov 11, 2015
1.x Remove all instances of Atomic*FieldUpdater
@akarnokd akarnokd merged commit c63fa2e into ReactiveX:1.x Nov 11, 2015
@akarnokd
Copy link
Member

Thanks for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants