Re: findColumn performance
Mark Matthews <[email protected]> Fri, 10 Oct 2008 14:22:07 -0500
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <[email protected]> |
On Oct 6, 2008, at 6:36 PM, Alex Burgel wrote: > ResultSetImpl.findColumn(String) uses a TreeMap with a comparator to > find the correct column number. > > For big result sets with a lot of columns, this can be a bit of a > bottleneck because the comparator must lower case the column names in > the map for each lookup. > > I have been profiling a very db intensive portion of my app and I see > findColumn as a hotspot. I use hibernate which gets columns by name, > rather than index. I know thats not the most efficient way. > > For these cases, i was thinking it will be much faster to lower case > all > the column names before putting them in the map. and then lower case > the > key before you do a lookup on the map. you can even use a hashmap in > this case which will give you a o(1) lookup time instead of o(log n). > > there will be a greater up front cost, tho i think that will be > negligble. > > has anyone looked into this? i wanted to put this out there before i > attempted a patch. > > --alex Alex, Alex, I see you've filed a bug on this, and your proposed patch (which I'm putting into 5.1.7) or fronting the lookup with another cache is a better approach, because it allocates less short-lived instances. The problem with .toLower() is that it creates a new String when it's called, and given that it will be called once for every column, for every row in the result set, that tends to get expensive as well. -Mark
PGP.sig
(application/pgp-signature, 194 B) - not displayed