[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Fast filter support in SAX2

  • From: Tyler Baker <tyler@i...>
  • To: David Megginson <david@m...>
  • Date: Mon, 29 Mar 1999 10:26:09 -0500

fast string hash
David Megginson wrote:

> Bill la Forge writes:
>
>  > It would be great if filters had the same advantages as parsers in
>  > being able to simply test for equality (x==y) rather than having to
>  > do a string comparison (x.equals(y)) when checking for a specific
>  > element or attribute name.
>
> Yes, but as someone (James Clark?) pointed out during the last round,
> with most serious applications you're going to end up doing hash
> lookups anyway, so the == doesn't buy you much.

That depends on your implementation of a hash table.  Also as of JDK 1.1.6 the equals method
for strings first tests for identity of the two string objects and then tests to see if the
length is the same and then tests for matching of each character in each string.  When dealing
with names in XML they are uniformly nothing more than symbols so in application code being
able to do something like this:

if (x == "foo")

is generally much faster than:

if (x.equals("foo"))

as you do not incur the overhead of calling one dynamic method.  Really it depends on your
code.  In an XML related technology I worked on I had lots of if-else statements that did
exactly this.  The parser I used presented the strings to the application as interned strings
and did significantly improve performance from using the equals method approach.

Another thing that I used for speeding up my applications is to have a special hash table for
interned strings.  Basically all that this table did was use System.identityHashcode() instead
of String.hashcode() to get a hash for the string.  In effect you use the Object.hashCode()
implementation.

It also depends a lot on your VM.  Some VM's are good enough with dynamic method invocation
that the difference between testing for string identity and string equality is neglibible.
The so-called Hotspot VM may even inline String.equals() into your code.

I suggest using the identity approach if possible as it is easier to read and maintain IMHO
and in the general case you may get significant speedups if your application does many string
comparisons.  If you need a faster hash table for strings build one yourself.

Tyler


xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i...
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo@i... the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@i... the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@i...)


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.