spaaarky21
spaaarky21

Reputation: 6868

Current Joda Time performance on Android?

I've heard performance concerns in the past about using Joda Time on Android. One specific example was an issue with the way that timezone data was loaded, which was causing a considerable amount of memory to remain allocated when it was no longer needed, for the life of the application. However, I believe some of those issues have also been addressed by this point.

Aside from general "I don't trust it" sentiment, :) are there any current issues that continue make Joda Time a poor choice for dealing with dates on Android?

Upvotes: 1

Views: 235

Answers (1)

kenny_k
kenny_k

Reputation: 3990

The problem still exists. The issue was the library's usage of ClassLoader.getResourceAsStream. This issue has NOT been fixed as of Android 6.0.1_r11 - see here for details.

As of this writing, the default ZoneInfoProvider still uses this mechanism - from the the current tip of master:

private InputStream openResource(String name) throws IOException {
    InputStream in;
    if (iFileDir != null) {
        in = new FileInputStream(new File(iFileDir, name));
    } else {
        final String path = iResourcePath.concat(name);
        in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
            public InputStream run() {
                if (iLoader != null) {
                    return iLoader.getResourceAsStream(path);
                } else {
                    return ClassLoader.getSystemResourceAsStream(path);
                }
            }
        });
        if (in == null) {
            StringBuilder buf = new StringBuilder(40)
                .append("Resource not found: \"")
                .append(path)
                .append("\" ClassLoader: ")
                .append(iLoader != null ? iLoader.toString() : "system");
            throw new IOException(buf.toString());
        }
    }
    return in;
}

In a few jumps, you can trace the usage of this problem method back to DateTimeZone.getProvider here:

public static Provider getProvider() {
    Provider provider = cProvider.get();
    if (provider == null) {
        provider = getDefaultProvider();
        if (!cProvider.compareAndSet(null, provider)) {
            provider = cProvider.get();
        }
    }
    return provider;
}

getDefaultProvider() will create the problematic ZoneInfoProvider class; so, if you use JodaTime with the default Provider, you will still have the same performance issues.

Upvotes: 1

Related Questions