- Revision
- 293837
- Author
- simon.fra...@apple.com
- Date
- 2022-05-05 08:55:46 -0700 (Thu, 05 May 2022)
Log Message
Optimize IPC Decoding for primitive types
https://bugs.webkit.org/show_bug.cgi?id=240106
Reviewed by Cameron McCormack.
Calls to memmove() showed up on profiles under Decoder::decodeFixedLengthData() for
primitive types. Allow the compiler to optimize these away by inlining Decoder::decodeFixedLengthData()
and related functions.
* Platform/IPC/Decoder.cpp:
(IPC::roundUpToAlignment): Deleted.
(IPC::alignedBufferIsLargeEnoughToContain): Deleted.
(IPC::Decoder::alignBufferPosition): Deleted.
(IPC::Decoder::bufferIsLargeEnoughToContain const): Deleted.
(IPC::Decoder::decodeFixedLengthData): Deleted.
* Platform/IPC/Decoder.h:
(IPC::roundUpToAlignment):
(IPC::alignedBufferIsLargeEnoughToContain):
(IPC::Decoder::alignBufferPosition):
(IPC::Decoder::bufferIsLargeEnoughToContain const):
(IPC::Decoder::decodeFixedLengthData):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (293836 => 293837)
--- trunk/Source/WebKit/ChangeLog 2022-05-05 15:48:01 UTC (rev 293836)
+++ trunk/Source/WebKit/ChangeLog 2022-05-05 15:55:46 UTC (rev 293837)
@@ -1,3 +1,27 @@
+2022-05-04 Simon Fraser <simon.fra...@apple.com>
+
+ Optimize IPC Decoding for primitive types
+ https://bugs.webkit.org/show_bug.cgi?id=240106
+
+ Reviewed by Cameron McCormack.
+
+ Calls to memmove() showed up on profiles under Decoder::decodeFixedLengthData() for
+ primitive types. Allow the compiler to optimize these away by inlining Decoder::decodeFixedLengthData()
+ and related functions.
+
+ * Platform/IPC/Decoder.cpp:
+ (IPC::roundUpToAlignment): Deleted.
+ (IPC::alignedBufferIsLargeEnoughToContain): Deleted.
+ (IPC::Decoder::alignBufferPosition): Deleted.
+ (IPC::Decoder::bufferIsLargeEnoughToContain const): Deleted.
+ (IPC::Decoder::decodeFixedLengthData): Deleted.
+ * Platform/IPC/Decoder.h:
+ (IPC::roundUpToAlignment):
+ (IPC::alignedBufferIsLargeEnoughToContain):
+ (IPC::Decoder::alignBufferPosition):
+ (IPC::Decoder::bufferIsLargeEnoughToContain const):
+ (IPC::Decoder::decodeFixedLengthData):
+
2022-05-05 Youenn Fablet <you...@apple.com>
Add SharedVideoFrameReader/SharedVideoFrameWriter logging for error cases
Modified: trunk/Source/WebKit/Platform/IPC/Decoder.cpp (293836 => 293837)
--- trunk/Source/WebKit/Platform/IPC/Decoder.cpp 2022-05-05 15:48:01 UTC (rev 293836)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.cpp 2022-05-05 15:55:46 UTC (rev 293837)
@@ -151,53 +151,6 @@
return Decoder::create(wrappedMessage.data(), wrappedMessage.size(), WTFMove(attachments));
}
-static inline const uint8_t* roundUpToAlignment(const uint8_t* ptr, size_t alignment)
-{
- // Assert that the alignment is a power of 2.
- ASSERT(alignment && !(alignment & (alignment - 1)));
-
- uintptr_t alignmentMask = alignment - 1;
- return reinterpret_cast<uint8_t*>((reinterpret_cast<uintptr_t>(ptr) + alignmentMask) & ~alignmentMask);
-}
-
-static inline bool alignedBufferIsLargeEnoughToContain(const uint8_t* alignedPosition, const uint8_t* bufferStart, const uint8_t* bufferEnd, size_t size)
-{
- // When size == 0 for the last argument and it's a variable length byte array,
- // bufferStart == alignedPosition == bufferEnd, so checking (bufferEnd >= alignedPosition)
- // is not an off-by-one error since (static_cast<size_t>(bufferEnd - alignedPosition) >= size)
- // will catch issues when size != 0.
- return bufferEnd >= alignedPosition && bufferStart <= alignedPosition && static_cast<size_t>(bufferEnd - alignedPosition) >= size;
-}
-
-bool Decoder::alignBufferPosition(size_t alignment, size_t size)
-{
- const uint8_t* alignedPosition = roundUpToAlignment(m_bufferPos, alignment);
- if (UNLIKELY(!alignedBufferIsLargeEnoughToContain(alignedPosition, m_buffer, m_bufferEnd, size))) {
- // We've walked off the end of this buffer.
- markInvalid();
- return false;
- }
-
- m_bufferPos = alignedPosition;
- return true;
-}
-
-bool Decoder::bufferIsLargeEnoughToContain(size_t alignment, size_t size) const
-{
- return alignedBufferIsLargeEnoughToContain(roundUpToAlignment(m_bufferPos, alignment), m_buffer, m_bufferEnd, size);
-}
-
-bool Decoder::decodeFixedLengthData(uint8_t* data, size_t size, size_t alignment)
-{
- if (!alignBufferPosition(alignment, size))
- return false;
-
- memcpy(data, m_bufferPos, size);
- m_bufferPos += size;
-
- return true;
-}
-
const uint8_t* Decoder::decodeFixedLengthReference(size_t size, size_t alignment)
{
if (!alignBufferPosition(alignment, size))
Modified: trunk/Source/WebKit/Platform/IPC/Decoder.h (293836 => 293837)
--- trunk/Source/WebKit/Platform/IPC/Decoder.h 2022-05-05 15:48:01 UTC (rev 293836)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.h 2022-05-05 15:55:46 UTC (rev 293837)
@@ -174,4 +174,51 @@
#endif
};
+inline const uint8_t* roundUpToAlignment(const uint8_t* ptr, size_t alignment)
+{
+ // Assert that the alignment is a power of 2.
+ ASSERT(alignment && !(alignment & (alignment - 1)));
+
+ uintptr_t alignmentMask = alignment - 1;
+ return reinterpret_cast<uint8_t*>((reinterpret_cast<uintptr_t>(ptr) + alignmentMask) & ~alignmentMask);
+}
+
+inline bool alignedBufferIsLargeEnoughToContain(const uint8_t* alignedPosition, const uint8_t* bufferStart, const uint8_t* bufferEnd, size_t size)
+{
+ // When size == 0 for the last argument and it's a variable length byte array,
+ // bufferStart == alignedPosition == bufferEnd, so checking (bufferEnd >= alignedPosition)
+ // is not an off-by-one error since (static_cast<size_t>(bufferEnd - alignedPosition) >= size)
+ // will catch issues when size != 0.
+ return bufferEnd >= alignedPosition && bufferStart <= alignedPosition && static_cast<size_t>(bufferEnd - alignedPosition) >= size;
+}
+
+inline bool Decoder::alignBufferPosition(size_t alignment, size_t size)
+{
+ const uint8_t* alignedPosition = roundUpToAlignment(m_bufferPos, alignment);
+ if (UNLIKELY(!alignedBufferIsLargeEnoughToContain(alignedPosition, m_buffer, m_bufferEnd, size))) {
+ // We've walked off the end of this buffer.
+ markInvalid();
+ return false;
+ }
+
+ m_bufferPos = alignedPosition;
+ return true;
+}
+
+inline bool Decoder::bufferIsLargeEnoughToContain(size_t alignment, size_t size) const
+{
+ return alignedBufferIsLargeEnoughToContain(roundUpToAlignment(m_bufferPos, alignment), m_buffer, m_bufferEnd, size);
+}
+
+inline bool Decoder::decodeFixedLengthData(uint8_t* data, size_t size, size_t alignment)
+{
+ if (!alignBufferPosition(alignment, size))
+ return false;
+
+ memcpy(data, m_bufferPos, size);
+ m_bufferPos += size;
+
+ return true;
+}
+
} // namespace IPC