candrews/HttpResponseCache — pull request #19 by bdonahue (2012-08-29 14:49:55+00:00)
Title: ISSUE-3: SimpleDateFormat can be extremely slow to parse

This ticket description is actually somewhat off as far as what the real issue is here.
I used the Android performance analysis tool to discover the real issue is these two lines:

new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
TimeZone.getTimeZone("UTC")

The root of the issue is that DateFormat is not thread safe, and is very slow to create.
I used the performance analysis tool to try a few approaches to solve the
issue and measure which was most performant. First I tried a simple synchronized access
to a single class wide copy of this variable. For an average test case of about 10 concurrent
downloads this increased the performance to ~5.4 times faster then the baseline. There was now
however a good amount of delay introduced by waiting for the synchronization. So an alternative
approach was tried where a pool of SimpleDateFormat's is created which can be used and recycled
back into the pool. With this approach the performance is now ~10.4 times faster. When I was
analyzing the performance this was by far the single most time consuming task, the entire
library is much faster as a result of this patch.