SAX2: Namespace proposal

David Megginson david at
Mon Dec 20 14:59:51 GMT 1999

Miles Sabin writes:
 > David Megginson wrote,
 > > Stefan Haustein wrote,
 > > > - building a new object seems some overhead at the first 
 > > > sight, but in JAVA also a new String is a new object...
 > >
 > > And that is why most parsers internalize strings rather than 
 > > creating new ones,
 > This isn't necessarily the best approach. Intern'ing a string
 > involves a lookup in a JVM-internal hash table. This table is
 > shared across all threads, and consequently has to be locked
 > against simultaneous reads and updates.

That's probably why most parsers have their own intern routines rather 
than using java.lang.String.intern -- at least, I wrote a custom
hashing and interning routine for AElfred that sped it up quite
significantly over (a) using java.lang.String.intern() or (b)
allocating a new string for every element name.  If I were doing it
over, though, I would actually call java.lang.String.intern once for
each of the strings in the intern table so that they were == to the
regular intern'ed versions.

 > It's also worth remembering that you've got to _already_ have
 > a String before you can intern it! If you've just created one
 > (eg. from a portion of a char array) then you're only going to
 > add overhead by doing an intern in addition.

Again, I avoided this problem by building my own intern and hashing
methods in AElfred.  There's no reason that a hash table should not be
able to use an array as a key -- Java's Hashtable just doesn't happen
to be designed that way.

All the best,


David Megginson                 david at

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at
Archived as: and on CD-ROM/ISBN 981-02-3594-1
To unsubscribe, mailto:majordomo at the following message;
unsubscribe xml-dev
To subscribe to the digests, mailto:majordomo at the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at

More information about the Xml-dev mailing list