Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 60452 invoked from network); 16 Nov 2002 23:39:48 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 16 Nov 2002 23:39:48 -0000 Received: (qmail 7135 invoked by uid 97); 16 Nov 2002 23:40:52 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 7119 invoked by uid 97); 16 Nov 2002 23:40:52 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 7107 invoked by uid 98); 16 Nov 2002 23:40:51 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Message-ID: <20021116233950.30016.qmail@web10410.mail.yahoo.com> Date: Sat, 16 Nov 2002 15:39:50 -0800 (PST) From: Jeff Varszegi Subject: [lang] Performance enhancement for SerializationUtils To: Jakarta Commons Developers List In-Reply-To: <20021116232506.16487.qmail@web10411.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Here is the code for the serialize(Serializable) method: public static byte[] serialize(Serializable obj) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); serialize(obj, baos); return baos.toByteArray(); } This can be sped up a significant amount just by using a different constructor for the ByteArrayInputStream instance, passing in a number higher than 32, so it constructs a bigger initial buffer than it otherwise would. Bumping up the initial buffer size to 128 worked about as well as bumping it up to 512 on my machine. This alone resulted in an overall 6% speed increase for the clone(Serializable) method on my machine. For the methods serialize(Serializable, OutputStream) and deserialize(InputStream) it may be desirable to wrap the passed streams in buffered streams. Serialization to/from streams is typically done for persistence, passing objects between JVMs, etc. and it's not hard to imagine someone passing in unbuffered streams in these situations... Jeff __________________________________________________ Do you Yahoo!? Yahoo! Web Hosting - Let the expert host your site http://webhosting.yahoo.com -- To unsubscribe, e-mail: For additional commands, e-mail: