osglworks / java-tool

Some simple common Java utilities
Apache License 2.0
52 stars 18 forks source link

BigLines - improve iterator performance #223

Closed greenlaw110 closed 4 years ago

greenlaw110 commented 4 years ago

At the moment iterating through the BigLines.iterator is running on O(n!), which will take extremely long to finish on a real big lines. App need to apply a special idiom to do the iteration to avoid the performance issue:

        int bufSize = 20000;
        int offset = 1;
        do {
            List<String> buf = bigLines.fetch(offset, bufSize);
            for (String line : buf) {
                // consume the line
            }
            offset += bufSize;
        } while (offset < lines);

The enhancement here is to encapsulate the above logic inside the iterator and simply application usage.