Re: Increase performance

cr <[email protected]> Wed, 09 May 2007 10:23:00 -0400
Newsgroups gmane.comp.mozilla.jrex
Message-ID <[email protected]>
The problem has to do with the fact that many calls to the mozilla DOM 
can only be safely accessed through the event queue thread.

In your case, when you invoke a DOM method from Java that requires one 
of these calls, the call is actually deferred until the mozilla event 
queue thread has a chance to make the call.  Your call then completes 
and returns the desired result.  Lots of overhead here.

There is a trick to get around this: make your Java call while the 
mozilla eqt is active.  If you have one of your event handlers, say your 
"document load" handler, do this, these calls should be made from within 
the eqt (this is off the top of my head, so there may be some details 
left out).  I have even gone so far as to build Java-side copies of the 
Mozilla DOM nodes so that I can access it more liberally.  I'll see if I 
can publish this code here.

--Chris

Billy wrote:
> Hi,
> I have some performance problems.
> 
> Here is one example:
> 
> 1) Extract a DOM document
> 2) Create a NodeList of all Elements with tag "A" (links)
> 3) do a for loop on all this nodes of the nodelist
> 4) Simulate a click event
> 
> That all takes over 1 second.
> 
> Step 1) and 2) take 0.1 seconds together and step 4) 0.1 seconds alone.
> Step 3) takes a lot of time. My for loop looks like that:
> 
> for (int i=0;i<nodelist.getLength();i++) {
>     if (nodelist.item(i).getAttribute("aAttribute").equals("foo"))
>       if (nodelist.item(i).getTextContent().toLowerCase().equals("sth")
>           <do a click ~ step 4>
> }
> 
> These 1.5 seconds are measured for a document with 16 links in the
> nodelist. Why does it take such a lot time? Is this caused by my system
> (Windows XP, 512MB RAM, 1,4 GHz Intel Centrino)
> or does JRex need a lot of time for iterating over a
> nodelist and get some tags? If so is there any way to improve the
> performance here?
> Thx and best regards.
> Billy