Solved

Sax Parser / Performance Question...

Posted on 2003-11-27
11
589 Views
Last Modified: 2013-11-23
I've been working on a card game applet.  This kind of sent me off on a tangent; I was working on the GUI, and I had nice data/code separation.. So I thought, hey why not store the data in a file?  Long story short, I've come up with a neat little swing markup language.  I had originally implemented it with an org.w3c.dom.DocumentBuilder.  Of course, once you start reading the JAXP spec, you can't help but notice how SAX is ending world hunger..</sarcasm>  Anyhow, I've gone to a validating SAX parser, complete with DTD..

I have 25 different tags, 10 of which are container tags; and 15 different attribute types...

As you might imagine, cramming all these into 2 methods - startElement() and endElement(); it wasn't pretty...  I was doing all kinds of string compares - in a linear fashion.  I wanted to go to a binary search, only I had to do something different (but similar)for each of the 25 tags.  My programming teacher suggested I use a hashing algorithm to elimate the string compares altogether..

So much for long story short!!!

Basically, I've created 2 simple nested interfaces:
protected interface Builder { Object make( Attributes attr ); }
protected interface Packager { void make( Tag t, SimpleStack temp ); }

Tag is just an Object and an int hashcode; SimpleStack is just that (32 lines of code). The idea is that I have an array for each interface - 2 function tables.  This enables me to do a binary search of the hashcode of each tag.  The result of the binary search indexes the function table, and the appropriate Builder/Packager is called.

Only now, my class is broken up into 40 files!!! arrgghh.  It creates a .class file for each interface in the table - XMLWindowFactory$23.class and so forth..

Please tell me there's a way to trick the compiler into leaving my tables in one file.. Like putting the interfaces in a Vector, or using a nested class instead...  Something...

A mouselistener doesn't create an extra .class file does it??  I'm basically doing the same thing..  Dang.. guess it does...

Think the binary search is worth the extra files??
0
Comment
Question by:ShawnCurry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9830576
You can package your classes up into a jar file...

Unfortunately, you can't stop java producing a class file for each inner/anonymous class :-(

But by making a jar out of them, you will only have to distribute one file instead of 40...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9830577
> Think the binary search is worth the extra files??

It does sound nice :-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9830588
If you create a manifest file like this:

----------

Manifest-Version: 1.0
Main-Class: classname

----------

save it as "MyManifest.txt", then make the jar file by:

jar -cvfm Cards.jar MyManifest.txt classes

(assuming all your classes are in a "classes" folder, and you want to make a jar file called "Cards.jar")
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 35

Expert Comment

by:TimYates
ID: 9830589
you can then run the application by:

java -jar Cards.jar
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9830765
Have a look at the powerful commons Digester. This can take an xml file of Cards and return you a collection of Java objects

http://jakarta.apache.org/commons/digester/
0
 
LVL 92

Expert Comment

by:objects
ID: 9833703
one class file per class, dats the rules :)
0
 
LVL 3

Author Comment

by:ShawnCurry
ID: 9839036
I apologize for the long explanation; I think most of it was necessary to see where I'm coming from..

I guess my real question for you experts is whether or not you think the binary search is worth the extra files...

Tim Yates..  Thanks for the nice explanation!  But uhh..  I already know all about jar files!!

I think having all these anonymous classes is increasing the size of the overall class (in bytes) significantly.  Correct me if i'm wrong, but there must be some kind of header information stored with each class file, right??  It creates 35k of class files from 18k of java code.

For example:

new Builder() {//combo
      public Object make( Attributes attr ) {
            JComboBox out = new JComboBox();
            ctrl[2].add( out );
            return out;
      }
},
new Builder() {//glass                                <-- THIS ONE IS 412 BYTES!!
      public Object make( Attributes attr ) {
            return null;//no object is created for glass pane
      }
},
new Builder() {//label
      public Object make( Attributes attr ) {
            JLabel out = new JLabel();
            for( int i = 0; i < attr.getLength(); i++ )
            {
                  if( attr.getQName(i).hashCode() == aname[13] )//title
                        out.setText( attr.getValue(i) );
            }
            ctrl[3].add( out );
            return out;
      }
},

Now, given the fact that many of these classes have only 3-4 lines of code to run, and the fact that I'm searching an array of 25 hashcodes (this will definately expand); is it worth it??  Keep in mind - this is an APPLET...  I'm trying to optimize the download performance as well (*I* have a dialup modem)

Granted, this question is probably better suited for the "Philosophy and Religion" "technology channel", but a little expert opinion would be greatly appreciated..

PS:  If someone were to come up with a little o-notation breakdown, bonus points would definately be involved!! :)

Thanks,
Shawn
0
 
LVL 92

Expert Comment

by:objects
ID: 9839902
jarring the files will decrease the size.
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
ID: 9839918
If you are using an inner class with the same functionality in >1 spots then you could make it a class in it's own right to avoid multiple copies of the same class being created.
0
 
LVL 92

Expert Comment

by:objects
ID: 9840257
0
 
LVL 3

Author Comment

by:ShawnCurry
ID: 9840323
I think that's what it'll utimately boil down to.  CheckBoxes and RadioButtons are virtually identical(title,tooltip,value); so are Labels,Menus,Menuitems, and Buttons(title,tooltip)...

I've already combined a couple tags...

Hmm...  Oh well..  Guess I'll actually sit down and decide once and for all what my tag/attribute sets will look like before I rewrite this too many more times..

Just added the tooltips, and I thought I'd add Icons and Images.  I think I can sqeeze toolbars in there too...  I really have my work cut out for me!!

Thanks,

Shawn
0

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question