Hi Lukas,
String internalisation would not improve jOOQ's performance but it would
save memory and it could improve performance of the application that uses
jOOQ.
Here is an example - an account entity has zero or more transactions:
- an ACCOUNT table has a String ID primary key and some other columns;
- a TRANSACTION table has a String ID primary key, a String ACCOUNT_ID
foreign key and some other columns;
Say that your records originate in multiple systems so you want make sure
that all keys are truly unique and you are
using UUID to generate all keys (UUID.randomUUID().toString()) so each key
will look something like this: ad202e80-709d-11e2-bcfd-0800200c9a66.
Now you are selecting transactions from the database for a given account
id. The query will return say 5,0000 transactions each with the same
ACCOUNT_ID foreign key 'ad202e80-709d-11e2-bcfd-0800200c9a66'. You will end
up with 5,0000 copies of the same foreign key
'ad202e80-709d-11e2-bcfd-0800200c9a66' allocated on the heap.
If you call intern() on each primary/foreign key value when you retrieve it
from the ResultSet - something like this:
public Transaction mapRow(ResultSet rs) throws SQLException {
Transaction tr = new Transaction();
tr.setId(rs.getString("ID").intern());
tr.setAccount(rs.getString("ACCOUNT_ID").intern());
....
return tr;
}
the keys will be internalised and only one copy will be created (JVM 6 - in
the permanent generation / JVM 7 - on the heap).
So you have saved space of 4,999 instances. There is a (small?) cost
associated with this as well. Every time you call intern()
on a string a search against the strings that are already in the pool is
performed (I guess hashing of some sort is involved here).
Additional bonus is that when calling equals() on the keys (directly or
when used in a hashed collection) identity operation '=='
is used first before per character comparison is performed. So this can
save a bit of work as well.
As far as the measurements/benchmarks are concerned the memory savings
could be quite significant but this obviously depends on the entity model.
To measure performance impact is not straighforward but I could have a go
at it at some point. Could you give me some pointers where to look in the
jOOQ for the ResultSet -> entity translation code?
Regards,
Adam
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.