commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Varszegi <jvarsz...@yahoo.com>
Subject [lang] Performance enhancement for SerializationUtils
Date Sat, 16 Nov 2002 23:39:50 GMT
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:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message