Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection

Showing 1-10 of 10 messages
Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection Rokesh Jankie 9/26/11 3:29 AM
Hi All,

I've been working on GWT for a while now and noticed something important and peculiar.
In GWT you code in Java and almost automatically assume Java garbage collection (because that's how you code).

you'll see that the callback is created like the code snippet below. I imagine that every GWT project will implement it like this.

The Use Case: Fill data in the new CellTable widget. The size of the data varied from 100 to 600 records.

If the onSuccess results in a lot of data and this event/callback is invoked lots of times (actually 3 to 5 times is enough) , on IE6, IE7,IE8 and IE9 there will be performance degradation. In other browsers
like Chrome, Firefox and Safari there is no performance loss noticed. 

After reading Joel Webber's note on Performance, I found out that it's not the component (like the CellTable) that causes this behavior,
but it was the callback creation. It seems that IE doesn't know how to garbage collection the "callback". So each time this "new AsyncCallback" is performed,
a memory leak occurred in IE browsers.

Since the Callback is stateless, we decided to create the callback only once  (static variable) and there was no performance loss anymore.
After clicking for a while, the performance was the same (even after inspecting the results of  some measurement tools).

This worked for us and even IE6 is blazingly fast. IE9 is now even faster that Chrome! No need for Chrome Frame Plugin (some organizations don't allow Plugins at all, think about that!)

Hopefully this tip works for you.

And Yes we have GWT in production. That company's browser policy is to use IE (now on 7, moving to 8). So this had to work or otherwise , it was a huge showstopper!

GWT applications do perform (even in older browsers), just make sure that critical parts of your code are carefully reviewed (especially on the "new").



 AsyncCallback callback = new AsyncCallback() {
   
public void onSuccess(Void result) {
     
// do some UI stuff to show success
   
}

   
public void onFailure(Throwable caught) {
     
// do some UI stuff to show failure
   
}
 
};

 
// (3) Make the call.......
Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection Juan Pablo Gardella 9/26/11 4:32 AM
Thanks for share!!!

2011/9/26 Rokesh <rja...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/3ZelaqGUGTcJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection Magno Machado 9/26/11 6:10 AM
interesting,

Would it be possible to implement this optimization at the compiler level, so that programmers don't have to care about this? I mean, only on the IE permutations, or for all permutations if it doesn't have negative effects on other browsers

Not something specific to callback, but for anonymous classes in general
--
Magno Machado Paulo
http://blog.magnomachado.com.br
http://code.google.com/p/emballo/
Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection ben fenster 9/26/11 7:26 AM
so just to understand just replace anonymous in call callback with a
variable will fix the problem ?
instead of:
call(new callback(){});

use :
callback c = new callback(){};
call(c);

?



On Sep 26, 1:29 pm, Rokesh <rjan...@gmail.com> wrote:
> Hi All,
>
> I've been working on GWT for a while now and noticed something important and
> peculiar.
> In GWT you code in Java and almost automatically assume Java garbage
> collection (because that's how you code).
>
> In this code sample:http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunicat...
> you'll see that the callback is created like the code snippet below. I
> imagine that every GWT project will implement it like this.
>
> The Use Case: Fill data in the new CellTable widget. The size of the data
> varied from 100 to 600 records.
>
> If the onSuccess results in a lot of data and this event/callback is invoked
> lots of times (actually 3 to 5 times is enough) , on IE6, IE7,IE8 and IE9
> there will be performance degradation. In other browsers
> like Chrome, Firefox and Safari there is no performance loss noticed.
>
> After reading Joel Webber's note on Performance, I found out that it's not
> the component (like the CellTable) that causes this behavior,
> but it was the callback creation. It seems that IE doesn't know how to
> garbage collection the "callback". So each time this "new AsyncCallback" is
> performed,
> a memory leak occurred in IE browsers.
>
> Since the Callback is stateless, we decided to create the callback only once
>  (*static *variable) and there was no performance loss anymore.
Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection Rokesh Jankie 9/26/11 7:42 AM
Almost there...


method doSomething (){


callback c = createCallback();


}


static AsyncCallback<?> callback = null;

AsyncCallback<?> createCallBack(){

   if (callback==null){
     callback = new AsyncCallback<Object>() {
               // implement onSuccess  
              //  implement onFailure
    }
       
    }
   return callback;

}


Since we are keeping the callbacks stateless, this really improved performance on IE!
Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection Nicolas Antoniazzi 9/26/11 8:26 AM
Interresting. But in this case, is not it the same problem for all anonymous classes ?
Do not you have this problem with event handler ?

myButton.addClickHanler(new ClickHandler() {
  public void onClick(ClickEvent e) {...}
}

2011/9/26 Rokesh Jankie <rja...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/0Xvfkgn9RjcJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection Rokesh Jankie 9/26/11 8:36 AM
No definitely not: This is only with the callback Class (and in combination with a lot of data).
Somehow the callback is not garbage collected properly in IE.

The GWT team covered this part (of (new ClickHandler)...)


And the last post of Joel Webber was definitely worth the read!

So in short: Only the callback ( AsyncCallback()) class we changed to a static class variable and that was it...No other code changes...

Again: java garbage collection is (apparently) NOT the same as Javascript garbage collection.

Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection Rob 10/12/12 10:41 AM
Hello can someone please help complete this sample. Maybe it is obvious to everyone out there but me but
callback c=createCallback();    does not seem to work. Exactly how do I instantiate my call back.
Do I have to
static AsyncCallback<MYOBJECT>  myCallback=null;
private AsyncCallback<MYOBJECT>  create_myCallback()
AsyncCallback<?> createCallBack(){

   if (myCallback==null){
     myCallback = new AsyncCallback<Object>() {
               // implement onSuccess  
              //  implement onFailure
    };
       
    } // end iff
   return callback;
}   // end of  constructor

// Implementation
AsyncCallback<MYOBJECT>  c=create_myCallback();
I guess so but then why the create mycallback when you meant AsyncCallback<MYOBJECT> ???  Or am I missing something here?
because:
myCallback c=create_myCallback();   // does not work
So I am pretty sure you meant the former:
e.g
AsyncCallback<MYOBJECT>  c=create_myCallback(); 
and not  
callback c = createCallback();
Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection Jens 10/12/12 12:30 PM
You have a static variable that is instantiated when its needed (lazy instantiation).


private static AsyncCallback<Person> findPersonCallback;

private AsyncCallback<Person> createFindPersonCallback() {
  if(findPersonCallback == null) {
     findPersonCallback = new AsyncCallback<Person>() { 
         //...... implement ..... 
     }
  }
  return findPersonCallback;
}

public void fetchByName(String name) {
   AsyncCallback<Person> callback = createFindPersonCallback();
   personService.findByName(name, callback);
}

-- J.
Re: Performance Tip for IE browsers : Java garbage collection is NOT Javascript garbage Collection tskardal 2/8/13 4:32 AM
Thanks for sharing. Very interesting!

Is this issue still around with the latest version of GWT and IE?