Deserializing using autobeans unbelievably slow in dev mode

298 views
Skip to first unread message

Christopher Piggott

unread,
Jun 10, 2012, 12:10:57 PM6/10/12
to google-we...@googlegroups.com
Hi,

I have a Jersey-Guice backend delivering some data to my gwt application for graphing.  The object returned is a JSON object delivered as JSONP (has to be cross-site).  The object contains a couple of simple fields and a map. For my testing, the map has 3 elements in it.  Each element of the map is a List of 850 objects, let's call them MyValue.  The MyValue has two properties, a double and a java.util.Date.

Currently I'm deserializing them as shown below.

My question is this: in development mode, the process of converting the JSONObject to a json string is insanely slow.  With my Map<String, ListMyValue>> of 3 entries of 850 rows, the serializing process is about 40 seconds on a Core 2 Duo 2.4 running linux, using Chromium as the browser.  (GWT version is 2.4).

My guess is that it's not the size of the object but the number of items.  I'm wondering if this is due to object creation churn as the string is built by creating string objects and appending them, meaning >2500 create-and-copy operations.

Questions:

1) If that's the case, is there anything I can do about it?
2) Is what I"m seeing typical?

public void onSuccess(JavaScriptObject jso) {
AutoBean<IHistoricalReport> report;
if (GWT.isProdMode()) {
/*
* In production mode, cast the JavaScriptObject
* to a Splittable and convert
*/
GWT.log("Production Mode");
Splittable splittable = (Splittable) jso;

GWT.log("decoding");
report = AutoBeanCodex.decode(beanFactory,
IHistoricalReport.class,
splittable);
} else {
/*
* In development mode, have to make a json string
* then decode from that
*/
GWT.log("Development Mode");
JSONObject jObj = new JSONObject(jso);
String json = jObj.toString();

GWT.log("decoding");
report = AutoBeanCodex.decode(beanFactory,
IHistoricalReport.class,
json);
}

IHistoricalReport h = report.as();
}
});

--Chris

Marko

unread,
Jun 11, 2012, 3:47:35 AM6/11/12
to google-we...@googlegroups.com
I think this is because of the Java-JavaScript Bridge in the DevMode. Application is partially running in Java and partially in JavaScript and the communication between the two is relatively slow. Because there are many cross-calls between Java and JavaScript within (de)serialization it takes so much time...

But I am not an expert on this and I may be wrong... I used to have similar problems on one of the GWT apps...

Thomas Broyer

unread,
Jun 11, 2012, 4:02:50 AM6/11/12
to google-we...@googlegroups.com


On Monday, June 11, 2012 9:47:35 AM UTC+2, Marko wrote:
I think this is because of the Java-JavaScript Bridge in the DevMode. Application is partially running in Java and partially in JavaScript and the communication between the two is relatively slow. Because there are many cross-calls between Java and JavaScript within (de)serialization it takes so much time...

But I am not an expert on this and I may be wrong... I used to have similar problems on one of the GWT apps...

Yes, that, and the use of JSONObject, which creates one JSONValue instance per value to be serialized.

Christopher, you'd better call JSON.stringify from JSNI when in Dev Mode.
Either that, or try Super Dev Mode ;-)

Travis Webb

unread,
Jul 12, 2012, 4:26:14 PM7/12/12
to google-we...@googlegroups.com
I am seeing this issue as well. Very painful. Two minutes to de-serialize 2,300 records on a Core i7. I would use super-dev but gwt-maven-plugin still hasn't released 2.5 yet...

Thomas Broyer

unread,
Jul 12, 2012, 6:03:33 PM7/12/12
to google-we...@googlegroups.com


On Thursday, July 12, 2012 10:26:14 PM UTC+2, Travis Webb wrote:
I would use super-dev but gwt-maven-plugin still hasn't released 2.5 yet...

I'll try to do the release this evening. exec-maven-plugin works well in the mean time: http://stackoverflow.com/questions/11063263/how-can-i-use-superdevmode-with-maven

Joseph Lust

unread,
Jul 14, 2012, 3:34:29 PM7/14/12
to google-we...@googlegroups.com
This is a well known issue. Of course it is because the browser plugins intercept all JS code and run it in the DevMode plugin (in Java) and then pass the result back to the browser. While Java code is fast, the overhead of the passing back and forth slows things down. Do something several thousand times and it becomes very noticeable. 

As the docs point out, in DevMode, some things that might be slow in JS will run fast (in Java), while other things that run slow in DevMode will actually run fast (i.e. deserialization) in Prod mode.

The work around I use (since my app deserializes ~15K objects), is to use a mock service in DevMode that only returns a few hundred results. This works well for fast debugging, and then when I run in Prod mode, I get the actual service and all 15K objects. For comparison, it was taking 45000ms to deserialize in DevMode and 100ms in ProdMode for 15K objects.

Hope that helps,

Sincerely,
Joseph

Travis Webb

unread,
Jul 14, 2012, 9:22:35 PM7/14/12
to google-we...@googlegroups.com
Hey Joe. Yea, I switched to using overlay types, which I probably should have used from the beginning. It's on the order of a thousand times faster.

Thomas, I see gwt-maven-plugin 2.5-rc1! I didn't realize you contributed to that project as well. Nice work, and very well done.

-tjw
Reply all
Reply to author
Forward
0 new messages