jabsorb optimization

58 views
Skip to first unread message

Piotr Przestrzelski

unread,
Jun 1, 2010, 12:24:06 PM6/1/10
to jabsorb-user, prze...@ie.ibm.com, martin.f...@ie.ibm.com, THIE...@ie.ibm.com
Hello,

We are using jabsorb to send several thousand of value objects from
server to a flash application running in a client browser.
We are using jabsorb 1.3.
The client flash application queries the server for the number of
objects to be downloaded and then sends requests for consecutive packs
one by one. The server sends packs of max 1000 value objects.
It appeared that the server side take unacceptably too long. On
JProfiler, I found out that almost all the time is spent in jabsorb on
marshalling the results and then serializing the result jabsorb object
into a string.

I did some optimization to jabsorb and managed to reduce the server
response by about 45 - 50%.
Here are the key modifications I did:
1. When transforming the result JSONObject into String, toString
method is used to transform the child objects to Strings, add
(concatenate) the child object string representations and return them
as parent object string representation. The consequence of this
approach is that String objects for child objects are created, used in
the parent object String concatenation and dropped.
Because the number of value objects and considerable nesting level
inside these objects, the number of created and then dropped String
objects was high, jabsorb was quickly running out of memory and had to
wait for garbage collection. This appeared to be a massive time-
waster.
Instead of using toString methods I create a single object of
StringBuilder class that is passed down the structure to be
serialized, every child JSONObject or JSONArray adds it's character
representation to this object instead of creating and returning a
String.
2. As mentioned already, I replaced StringBuffer objects with
StringBuilder objects. The difference is that StringBuilder is not
synchronized, which should be fine here, because the jabsorb response
is serialized in a single thread.
3. I removed the class ProcessedObject completely, replaced it with 3
IdentityHashMap objects in SerializerState. Thanks to this I avoid
massive allocations (and garbage collection) of ProcessedObject
wrapper class.
4. There are a few more customized optimizations - the initial
capacity of Hash Maps, ArrayList and the result StringBuilder is
parametrised by the size of response (if the response is an array,
initial capacities are multipications of the array length).

Please, let me know if you see any issues with this approach.
Also, please let me know if you have any questions. If you find value
in using my approach to optimize jabsorb, I'll be happy to provide
sufficient clarifications.

Kind Regards,
Piotr

Arthur Blake

unread,
Jun 1, 2010, 2:49:21 PM6/1/10
to jabsor...@googlegroups.com
Are your changes to the org.json package, the org.jabsorb package or both?
Can you submit your changes as a patch?


--
You received this message because you are subscribed to the Google Groups "jabsorb-user" group.
To post to this group, send email to jabsor...@googlegroups.com.
To unsubscribe from this group, send email to jabsorb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jabsorb-user?hl=en.


Piotr Przestrzelski

unread,
Jun 2, 2010, 5:55:43 AM6/2/10
to jabsorb-user, prze...@ie.ibm.com, martin.f...@ie.ibm.com, THIE...@ie.ibm.com
Hi Arthur,

My changes are both in org.json and org.jabsorb. Here's the list of
changed files:

Modified files
--------------------------------------------------------
src\org\jabsorb\serializer\impl\ArraySerializer.java
src\org\jabsorb\serializer\impl\BeanSerializer.java
src\org\jabsorb\serializer\AbstractSerializer.java
src\org\jabsorb\serializer\AccessibleObjectResolver.java
src\org\jabsorb\serializer\SerializerState.java
src\org\jabsorb\JSONRPCResult.java
src\org\jabsorb\JSONSerializer.java
src\org\json\JSONArray.java
src\org\json\JSONObject.java
src\org\json\JSONString.java

Removed file
--------------------------------------------------------
src\org\jabsorb\serializer\ProcessedObject.java

I'm going to submit the changes as a path, but first I need to get
approval from copmany's legal dep. (But I don't expect problems here).

Cheers,
Piotr
> > jabsorb-user...@googlegroups.com<jabsorb-user%2Bunsubscribe@google groups.com>
> > .
Reply all
Reply to author
Forward
0 new messages