OpenNTF / org.openntf.domino

Open replacement for lotus.domino package in HCL Domino
Apache License 2.0
65 stars 34 forks source link

Improved performance of ViewNavigatorEntryIterator #161

Closed 4ndyc closed 4 years ago

4ndyc commented 7 years ago

Performance of the ViewNavigatorEntryIterator can be boosted by around 20% - 30% compared to the existing implementation by altering it to use ViewNavigator.getNext() rather than ViewNavigator.getNext(ViewEntry) - see http://linqed.eu/2017/05/12/convenience-at-a-cost-comparing-domino-java-apis-performance-oda-legacy-jna/. I've tested the following implementation, comments etc excluded for brevity:

public class ViewNavigatorEntryIterator implements Iterator<ViewEntry> {

    private transient ViewNavigator navigator_;
    private transient ViewEntry currentEntry_;
    private transient ViewEntry nextEntry_;

    public ViewNavigatorEntryIterator(ViewNavigator navigator) {
        navigator_ = navigator;
        nextEntry_ = navigator_.getFirst();
    }

    public boolean hasNext() {
        return nextEntry_ != null;
    }

    public ViewEntry next() {
        if (hasNext()) {
            currentEntry_ = nextEntry_;
            nextEntry_ = navigator_.getNext();
            return currentEntry_;
        } else {
            return null;
        }
    }

    public void remove() {
        // Not implemented
    }

}
the-ntf commented 7 years ago

Wow that's great insight. I will check this in tonight!

On May 16, 2017 15:33, "4ndyc" notifications@github.com wrote:

Performance of the ViewNavigatorEntryIterator can be boosted by around 20% - 30% compared to the existing implementation by altering it to use ViewNavigator.getNext() rather than ViewNavigator.getNext(ViewEntry) - see http://linqed.eu/2017/05/12/convenience-at-a-cost- comparing-domino-java-apis-performance-oda-legacy-jna/ http://url. I've tested the following implementation, comments etc excluded for brevity:

public class ViewNavigatorEntryIterator implements Iterator {

private transient ViewNavigator navigator; private transient ViewEntry currentEntry; private transient ViewEntry nextEntry_;

public ViewNavigatorEntryIterator(ViewNavigator navigator) { navigator = navigator; nextEntry = navigator_.getFirst(); }

public boolean hasNext() { return nextEntry_ != null; }

public ViewEntry next() { if (hasNext()) { currentEntry = nextEntry; nextEntry = navigator.getNext(); return currentEntry_; } else { return null; } }

public void remove() { // Not implemented }

}

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/OpenNTF/org.openntf.domino/issues/161, or mute the thread https://github.com/notifications/unsubscribe-auth/ACoex9_vRFnJoYMUAxrOiZkmchgZw0Gqks5r6gfjgaJpZM4NdCsn .

4ndyc commented 7 years ago

Although the results still stand, on further investigation ViewNavigator.getNext(ViewEntry) doesn't look like the culprit. The actual cause of the problem is the call to hasNext in the iterator's next method, which increases the number of API calls.