Hello,

Concerned by the performances of HSQLDB, I've made an audit (using Together
6.0).
(see attachment)

I've take a look on the source code of hsqldb and find some easy
improvments which can
speed up hsqldb. In fact, this is some rules to keep in mind while coding:

-1-
int size = Vector.size();
for( int i = 0; i < size; i++ )
{}

is better than

for( int i = 0; i < Vector.size(); i++ )
{}

it's the same for arrays: size = array.length

-2-
Vector is a synchronized object, ArrayList do the same but is not
synchronized.
Although a RDBMS must provide transaction isolation and thus Vector might
be
useful to do that, I think that sometime, hsqldb could use ArrayList
objects instead
of Vector. This remark applies to Hashtable vs HashMap too.

-3-
I've made some performance tests:

Y= 100,000 times and X = 1,000,000 times, remark the different results
between Vector (V) and ArrayList (A)!
(Embedded image moved to file: pic16827.pcx)

-3.1-
Y Creation of Vector: 3345ms
Y Creation of ArrayList: 3234ms

-3.2-
Y addElement (V): 1292ms
Y add (A): 1602ms

-3.3-
Y synchronized addElement (V): 1262ms
Y synchronized add (A): 1552ms

it means:
synchronized( Vector )
{
     size = Vector.size();
     for ( int i = 0; i < size; i++ )
      Vector.addElement( );
}

-3.4-
X elementAt (V): 350ms

-3.5-
X synchronized elementAt (V): 350ms

-3.6-
X get (V): 361ms
X get (A): 291ms

-3.7-
X synchronized get (V): 340ms
X synchronized get (A): 300ms

-3.8-
X Iterator (V): 912ms
X Iterator (A): 792ms

it means:
for( Iterator i = Vector.iterator(); i.hasNext(); )
      i.next();

-3.9-
X synchronized Iterator (V): 851ms
X synchronized Iterator (A): 801ms


As you can see, synchronized access to a Vector in a loop is faster but not
for ArrayList
(because it's already synchronized). Iterator must not be used (if it's
possible).



Regards,
Loic Lefevre

(See attached file: hsqldb_1_7_0_AUDIT.zip)


This message and any attachments (the "message") is
intended solely for the addressees and is confidential. 
If you receive this message in error, please delete it and 
immediately notify the sender. Any use not in accord with 
its purpose, any dissemination or disclosure, either whole 
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message. 
BNP PARIBAS (and its subsidiaries) shall (will) not 
therefore be liable for the message if modified. 

                ---------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le 
"message") sont etablis a l'intention exclusive de ses 
destinataires et sont confidentiels. Si vous recevez ce 
message par erreur, merci de le detruire et d'en avertir 
immediatement l'expediteur. Toute utilisation de ce 
message non conforme a sa destination, toute diffusion 
ou toute publication, totale ou partielle, est interdite, sauf 
autorisation expresse. L'internet ne permettant pas 
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce 
message, dans l'hypothese ou il aurait ete modifie.

Attachment: pic16827.pcx
Description: Binary data

Attachment: hsqldb_1_7_0_AUDIT.zip
Description: Zip archive

Reply via email to