Skip to content

Journal size improvement #28

Closed
jonathangerbaud opened this Issue Jan 3, 2013 · 2 comments

3 participants

@jonathangerbaud

After opening and closing an android app using Alexander Blom webimageloader library several times, the startup time keeps increasing. In fact, the journal file is never rebuilt and keeps getting bigger (in my case almost 1Mb, 5 seconds of processing !).

After hours of investigation, I discovered that the readJournalFile method doesn't count the redundant Operation number and thus is set to 0 after each startup. Therefore, the journalRebuildRequired method always return false and the journal is never rebuilt.

    private void readJournalLine(String line) throws IOException {
        int firstSpace = line.indexOf(' ');
        if (firstSpace == -1) {
            throw new IOException("unexpected journal line: " + line);
        }

        int keyBegin = firstSpace + 1;
        int secondSpace = line.indexOf(' ', keyBegin);
        final String key;
        if (secondSpace == -1) {
            key = line.substring(keyBegin);
            if (firstSpace == REMOVE.length() && line.startsWith(REMOVE)) {
                //___ ADD THIS ____
                redundantOpCount++;
                //_________________
                lruEntries.remove(key);
                return;
            }
        } else {
            key = line.substring(keyBegin, secondSpace);
        }

        Entry entry = lruEntries.get(key);
        if (entry == null) {
            entry = new Entry(key);
            lruEntries.put(key, entry);
        }

        if (secondSpace != -1 && firstSpace == CLEAN.length() && line.startsWith(CLEAN)) {
            String[] parts = line.substring(secondSpace + 1).split(" ");
            entry.readable = true;
            entry.currentEditor = null;
            entry.setLengths(parts);

            //___ ADD THIS ____
            //if previous read or dirty
            if (lruEntries.get(key) != null)
                redundantOpCount++;
            //_________________
        } else if (secondSpace == -1 && firstSpace == DIRTY.length() && line.startsWith(DIRTY)) {
            entry.currentEditor = new Editor(entry);
        } else if (secondSpace == -1 && firstSpace == READ.length() && line.startsWith(READ)) {
            //___ ADD THIS ____
                redundantOpCount++;
            //_________________
            // this work was already done by calling lruEntries.get()
        } else {
            throw new IOException("unexpected journal line: " + line);
        }
    }
@swankjesse
Collaborator

Wow, nice find. Should fix this here as well as in AOSP.

@JakeWharton
Owner

Great catch! Released with 1.3.1.

@JakeWharton JakeWharton closed this Jan 3, 2013
@elliottsj elliottsj pushed a commit to elliottsj/ftw-android that referenced this issue Dec 31, 2013
@swankjesse swankjesse Track redundant ops when opening the cache. f6fca81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.