[jcifs] Performance improvement
Michael B Allen
ioplex at gmail.com
Thu Dec 20 23:27:48 MST 2012
On Thu, Dec 20, 2012 at 6:26 PM, Johan Hägre <johan at hagre.net> wrote:
> I have recently started using jcifs-1.3.17 to add support for direct access
> to SMB shares in an old web application I have used for years, it used to
> read the files from the local filesystem. When I replaced the regular File
> objects with SmbFile objects and started the application the performance was
> horrible, what used to take a second took several minutes (loading the start
> page). After a week or so of investigating the problem I have found the
> cause, it seems that the equals() and hashCode() methods of SmbFile are
> quite slow. My application caches folder settings in a HashMap using the
> SmbFile objects as keys so it was heavily affected by this. By overriding
> the mentioned methods the performance is about the same as when using the
> local file system, my implementation looks like this.
> Now to my question, the code seems to work OK and the performance is clearly
> a lot better (I measured the equals method to take about 30ms on my laptop
> before, now it's less than 1ms). But since I'm no expert on either the jcifs
> code or the SMB protocol it would be great if someone with more knowledge
> took a look at the problem and either solved it in a better way or if my
> solution is OK simply included my code in a coming release.
Unfortunately the API already defines those methods for performing a
more logical comparison by looking at server addresses and
canonicalized paths and so on. So yes, they will be horrendously slow
compared to your average hashCode method that just tries to produce a
vaguely unique number.
As for your quick and dirty methods, they're probably fine. But you
might want to grep through the code looking for equals and hashCode
calls. There might actually be something that depends on the logical
comparison. But I doubt it. I think your code will work just fine.
I have added this issue to the infamous "2.0" TODO list. I think it
would be better if these methods were the quick and dirty variety for
usage with HashMaps and such. There could be another method for
peforming the logical comparison that is implemented right now.
Michael B Allen
Java Active Directory Integration
More information about the jCIFS