Skip to content

A set of stateless operators that don't need to be instantiated #2335

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 2 commits into from
Jan 21, 2015

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Jan 6, 2015

for lift() all the time.

@benjchristensen
Copy link
Member

That's a nice change. This should improve GC behavior. Have you been able to measure it?

@davidmoten
Copy link
Collaborator

There's a javadoc typo that has been copy pasted throughout: 'an singleton instance'.

@akarnokd
Copy link
Member Author

akarnokd commented Jan 6, 2015

I haven't measured the GC gain; but I guess your use case that required queue pooling might benefit from another 16 bytes of allocation-reduction.

@akarnokd akarnokd changed the title A first set of stateless operators that don't need to be instantiated A set of stateless operators that don't need to be instantiated Jan 7, 2015
@akarnokd
Copy link
Member Author

The following program prints 240 bytes/instance on head and 225 on this PR; that is ~15 MB of heap saved

public class MergeAlloc {
    public static void main(String[] args) {
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();
        long initial = memHeap.getUsed();

        int m = 1_000_000;

        System.out.printf("Starting: %.3f MB%n", initial / 1024.0 / 1024.0);

        List<Observable<Integer>> list = new LinkedList<>();

        for (int i = 0; i < m; i++) {
            list.add(Observable.merge(Observable.just(1), Observable.just(2)));
        }

        memHeap = memoryMXBean.getHeapMemoryUsage();
        long after = memHeap.getUsed();
        System.out.printf("Starting: %.3f MB%n", after / 1024.0 / 1024.0);

        System.out.printf("Cost: %d bytes/item", (after - initial) / m);
    }
}

@akarnokd
Copy link
Member Author

Triggering re-Travis.

@akarnokd akarnokd closed this Jan 21, 2015
@akarnokd akarnokd reopened this Jan 21, 2015
akarnokd added a commit that referenced this pull request Jan 21, 2015
A set of stateless operators that don't need to be instantiated
@akarnokd akarnokd merged commit ec60fa4 into ReactiveX:1.x Jan 21, 2015
@akarnokd akarnokd deleted the StatelessOperators branch January 21, 2015 12:00
@benjchristensen benjchristensen mentioned this pull request Feb 3, 2015
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.

3 participants