RE: [JBoss-dev] Optimizing MarshalledObject, or variants thereof

2002-08-19 Thread Sacha Labourey

hello Rickard,

I've implemented your suggestion in JBoss and found strange results (under
W2K, both 1.3 and 1.4 JVM with hotspot enabled).

The difference is frequently not significant at all: sometimes the
optimized version is faster, sometimes not (and by running tens of
thousands of serialisations, after a hotspot-warm-up)

In fact, when using the toByteArray'ed version, System.arraycopy is used
internally: this is the only additional step that differentiates both
versions. And if you take a look at it, as all elements are of the same type
(byte), the arraycopy is implemented as a C memmove. Maybe, internally,
the memmove is handled by the OS memory manager as a simple duplicated view
of the same memory page that is only *really* copied if/once a modification
occurs on this page (copy-on-write). In this case, as no modification is
performed, no copy could be done. Thus, the cost may not be that big (except
for the native call to System.arraycopy). But it may change depending on the
OS/JVM.

It is just an attempt to understand, not a strong in-depth analysis.

Any other opinion?

Cheers,


Sacha




 -Message d'origine-
 De : [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]De la part de
 Rickard Öberg
 Envoyé : mardi, 13 août 2002 15:01
 À : [EMAIL PROTECTED]
 Objet : [JBoss-dev] Optimizing MarshalledObject, or variants thereof


 Hey

 I just found out a way to optimize the use of MarshalledObject, if it's
 used to send stuff over the network (JBoss has it's own version, but it
 has the same basic code).

 The MO serializes the data into a ByteArrayOutputStream, which then is
 toByteArray'ed in order to get the data. This is bad, since the data is
 then copied into a new array of the same length. This may not mean much,
 but if you're doing it all the time it makes a difference.

 There's a trick to get around this: simply store the BAOS in an instance
 variable of the MO, and call out.write(BAOS.size());BAOS.writeTo(out);
 during serialization. This will avoid the copy. Read the data during
 deserialization, and the rest is the same.

 This simple trick will hence reduce the number of byte arrays created by
 50%. You'll probably want to introduce this fix into MarshalledValue,
 and any other place where MO's are used.

 /Rickard

 --
 Rickard Öberg
 [EMAIL PROTECTED]
 Senselogic

 Got blog? I do. http://dreambean.com



 ---
 This sf.net email is sponsored by: Dice - The leading online job board
 for high-tech professionals. Search and apply for tech jobs today!
 http://seeker.dice.com/seeker.epl?rel_code1
 ___
 Jboss-development mailing list
 [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/jboss-development




---
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1refcode1=vs3390
___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



RE: [JBoss-dev] Optimizing MarshalledObject, or variants thereof

2002-08-13 Thread marc fleury

thanks

marcf

PS: want to get your RW back? do you still have it?

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED]] On 
 Behalf Of Rickard Öberg
 Sent: Tuesday, August 13, 2002 9:01 AM
 To: [EMAIL PROTECTED]
 Subject: [JBoss-dev] Optimizing MarshalledObject, or variants thereof
 
 
 Hey
 
 I just found out a way to optimize the use of 
 MarshalledObject, if it's 
 used to send stuff over the network (JBoss has it's own 
 version, but it 
 has the same basic code).
 
 The MO serializes the data into a ByteArrayOutputStream, 
 which then is 
 toByteArray'ed in order to get the data. This is bad, since 
 the data is 
 then copied into a new array of the same length. This may not 
 mean much, 
 but if you're doing it all the time it makes a difference.
 
 There's a trick to get around this: simply store the BAOS in 
 an instance 
 variable of the MO, and call 
 out.write(BAOS.size());BAOS.writeTo(out); 
 during serialization. This will avoid the copy. Read the data during 
 deserialization, and the rest is the same.
 
 This simple trick will hence reduce the number of byte arrays 
 created by 
 50%. You'll probably want to introduce this fix into MarshalledValue, 
 and any other place where MO's are used.
 
 /Rickard
 
 -- 
 Rickard Öberg
 [EMAIL PROTECTED]
 Senselogic
 
 Got blog? I do. http://dreambean.com
 
 
 
 ---
 This sf.net email is sponsored by: Dice - The leading online 
 job board for high-tech professionals. Search and apply for 
 tech jobs today! http://seeker.dice.com/seeker.epl?rel_code1
 ___
 Jboss-development mailing list [EMAIL PROTECTED]
 https://lists.sourceforge.net/lists/listinfo/jboss-development
 



---
This sf.net email is sponsored by: Dice - The leading online job board
for high-tech professionals. Search and apply for tech jobs today!
http://seeker.dice.com/seeker.epl?rel_code1
___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development



Re: [JBoss-dev] Optimizing MarshalledObject, or variants thereof

2002-08-13 Thread Rickard Öberg

marc fleury wrote:
 thanks
 
 marcf
 
 PS: want to get your RW back? do you still have it?

No, I'm cool without it. I just happened to do this optimization in some 
code I wrote for my new AOP framework, and remembered that MO's were 
being used quite heavily for calls in JBoss. That's all.

/Rickard

-- 
Rickard Öberg
[EMAIL PROTECTED]
Senselogic

Got blog? I do. http://dreambean.com



---
This sf.net email is sponsored by: Dice - The leading online job board
for high-tech professionals. Search and apply for tech jobs today!
http://seeker.dice.com/seeker.epl?rel_code1
___
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development