This is an automated email from the ASF dual-hosted git repository. papegaaij pushed a commit to branch performance-improvements-10.x in repository https://gitbox.apache.org/repos/asf/wicket.git
commit 56a22a0c822eb2813d523d8ed4ad434ad743cc99 Author: Emond Papegaaij <[email protected]> AuthorDate: Fri Sep 11 22:07:10 2026 +0200 Serialize pages into a buffer that grows by chaining JavaSerializer wrote into a java.io.ByteArrayOutputStream with no initial size, which starts at 32 bytes and grows by copying everything written so far into a buffer of twice the size. A page of any substance outgrows that several times over, and every one of those copies is thrown away again immediately. Wicket already has a ByteArrayOutputStream that chains a new buffer instead. Starting it at 4kB means a modest page never has to grow it at all. Measured over a page of 500 components, 37924 bytes serialized: 256714 -> 214763 bytes allocated per operation, -16%. Backported from master. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --- .../java/org/apache/wicket/serialize/java/JavaSerializer.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java b/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java index a91a1c4ef2..73b5cfb691 100644 --- a/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java +++ b/wicket-core/src/main/java/org/apache/wicket/serialize/java/JavaSerializer.java @@ -17,7 +17,6 @@ package org.apache.wicket.serialize.java; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.NotSerializableException; @@ -40,6 +39,7 @@ import org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream; import org.apache.wicket.core.util.objects.checker.ObjectSerializationChecker; import org.apache.wicket.serialize.ISerializer; import org.apache.wicket.settings.ApplicationSettings; +import org.apache.wicket.util.io.ByteArrayOutputStream; import org.apache.wicket.util.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,6 +67,9 @@ public class JavaSerializer implements ISerializer } + /** Where the serialization buffer starts, sized so that a modest page never has to grow it. */ + private static final int INITIAL_BUFFER_SIZE = 4096; + /** * The key of the application which can be used later to find the proper {@link IClassResolver} */ @@ -88,7 +91,11 @@ public class JavaSerializer implements ISerializer { try { - final ByteArrayOutputStream out = new ByteArrayOutputStream(); + // Wicket's ByteArrayOutputStream chains a new buffer when it runs out of room, where + // java.io's copies everything written so far into a buffer of twice the size. A page + // of any substance outgrows the initial buffer several times over, and each of those + // copies is thrown away again immediately. + final ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE); ObjectOutputStream oos = null; try {
