I have uploaded a patch (
DERBY-212-parsePKGNAMCSN.diff) which changes
the following files:
The patch only addresses the reported problems in
parsePKGNAMCSN(). This method parses a PKGNAMCSN object and returns a
string with all the fields concatenated. When other parts of the code
need one of the fields, a StringTokenizer has to be used to fetch the
field. This approach leads to a lot of unnecessary object allocation
and string parsing.
What the patch does is basically:
1) Instead of returning a string from parsePKGNAMCSN(), an object of
type Pkgnamcsn is returned. This object has accessor methods
which are much cheaper than the methods in StringTokenizer.
2) Since the strings read in parsePKGNAMCSN() often are repeated,
reusing the strings seemed like a good idea. To achieve this, the
class DRDAString was implemented. That class stores a byte array
and can return the array as a string. Strings are cached to avoid
allocation and decoding if the byte array has not
changed. Pkgnamcsn objects are also cached, so a new one is only
allocated when one of its fields has changed.
3) In Database.java, a substring of the original PKGNAMCSN string
was used as a hash key. With this patch, a new internal class
StmtKey is added to Database. That class implements equals() and
hashCode() in a way that enables its use as a hash key instead of
the substring that was used originally. Caching is also
implemented to avoid allocating new StmtKey objects when an old
one can be reused.
Derbyall ran without errors.
I have also attached graphs showing the performance improvements. The
graphs show the throughput of 1-100 clients running read-only load
(select one row from a table which is in the page cache). The file
throughput.png shows the throughput as transactions per second with
and without the patch, and throughput-normalized.png shows the
increase in percent for different number of clients. The graphs
indicate a speedup of 5-8% with this particular load.
Could someone please review and comment on the patch?