From 564c7ae5b2620be57fcb1a26c17e89f576a1bdd1 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 24 Oct 2026 02:15:51 -0700 Subject: [PATCH] revert: back out buffer trailer reservation pending a container-neutral design (#198) This reverts f45fff0d8f0923017a87baf439d574565b25fdd0 (#195), resolving overlap with #196 without restoring its Error.cause serialization changes. The fixed small-payload Worker postMessage gate measured a median paired ratio of 1.053 against a maximum 1.03, with 9 of 10 pairs slower. Remove the per-container bookkeeping pending a design that charges only large-Buffer paths. Preserve the #197 pre-connect SNI fix and the historical #195 changelog entry, with a new backout note. --- CHANGELOG.md | 2 ++ .../bindings/webcore/SerializedScriptValue.cpp | 15 ++------------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 088c4a8ef6b9..9625ab925567 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Back out Error.cause serialization (#192, #194) pending a performance-neutral design. +- Back out Buffer trailer reservation (#195) for its small-payload serialization cost, pending a design that charges only large-Buffer paths. + - Avoid an extra payload copy when structured cloning or messaging a Buffer or ArrayBuffer inside a container, without changing serialized bytes. - Sync oven-sh/bun through `ad4089bf49d9f4c3ab7c8d95a58f3e0f0f186054`, including lint, format, binding, WebSocket and SQL updates, while retaining the fork runtime and CI contracts. diff --git a/src/jsc/bindings/webcore/SerializedScriptValue.cpp b/src/jsc/bindings/webcore/SerializedScriptValue.cpp index cfd2b3ff01ef..e117932d0741 100644 --- a/src/jsc/bindings/webcore/SerializedScriptValue.cpp +++ b/src/jsc/bindings/webcore/SerializedScriptValue.cpp @@ -836,7 +836,6 @@ class CloneSerializer : public CloneBase { { if (!startObjectInternal(object)) return false; - m_pendingContainerBytes += sizeof(TerminatorTag); write(ObjectTag); return true; } @@ -846,7 +845,6 @@ class CloneSerializer : public CloneBase { if (!startObjectInternal(array)) return false; - m_pendingContainerBytes += sizeof(TerminatorTag); unsigned length = array->length(); write(ArrayTag); write(length); @@ -858,7 +856,6 @@ class CloneSerializer : public CloneBase { if (!startObjectInternal(set)) return false; - m_pendingContainerBytes += sizeof(uint8_t) + sizeof(TerminatorTag); write(SetObjectTag); return true; } @@ -868,15 +865,12 @@ class CloneSerializer : public CloneBase { if (!startObjectInternal(map)) return false; - m_pendingContainerBytes += sizeof(uint8_t) + sizeof(TerminatorTag); write(MapObjectTag); return true; } void endObject() { - ASSERT(m_pendingContainerBytes >= sizeof(TerminatorTag)); - m_pendingContainerBytes -= sizeof(TerminatorTag); write(TerminatorTag); } @@ -1315,7 +1309,7 @@ class CloneSerializer : public CloneBase { if (arrayBuffer->isResizableOrGrowableShared()) { uint64_t byteLength = arrayBuffer->byteLength(); - if (!m_buffer.tryReserveCapacity(static_cast(m_buffer.size()) + sizeof(uint8_t) + sizeof(uint64_t) * 2 + byteLength + m_pendingContainerBytes)) [[unlikely]] { + if (!m_buffer.tryReserveCapacity(static_cast(m_buffer.size()) + sizeof(uint8_t) + sizeof(uint64_t) * 2 + byteLength)) [[unlikely]] { code = SerializationReturnCode::DataCloneError; return true; } @@ -1328,9 +1322,7 @@ class CloneSerializer : public CloneBase { } uint64_t byteLength = arrayBuffer->byteLength(); - // Reserve mandatory container trailers before copying the payload so - // closing the containers cannot copy the payload again. - if (!m_buffer.tryReserveCapacity(static_cast(m_buffer.size()) + sizeof(uint8_t) + sizeof(uint64_t) + byteLength + m_pendingContainerBytes)) [[unlikely]] { + if (!m_buffer.tryReserveCapacity(static_cast(m_buffer.size()) + sizeof(uint8_t) + sizeof(uint64_t) + byteLength)) [[unlikely]] { code = SerializationReturnCode::DataCloneError; return true; } @@ -1988,7 +1980,6 @@ class CloneSerializer : public CloneBase { } } #endif - unsigned m_pendingContainerBytes { 0 }; ObjectPool m_objectPool; ObjectPool m_transferredMessagePorts; ObjectPool m_transferredArrayBuffers; @@ -2173,7 +2164,6 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) mapIteratorStack.removeLast(); RETURN_IF_EXCEPTION(scope, SerializationReturnCode::ExistingExceptionError); // Keep the legacy property-section markers, but clone only Map entries. - m_pendingContainerBytes -= sizeof(uint8_t); write(NonMapPropertiesTag); endObject(); inputObjectStack.removeLast(); @@ -2220,7 +2210,6 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in) if (!hasNext) { setIteratorStack.removeLast(); // Older readers still expect an empty own-property section after Set entries. - m_pendingContainerBytes -= sizeof(uint8_t); write(NonSetPropertiesTag); endObject(); inputObjectStack.removeLast();