Title: [137328] trunk/Source/WebKit2
- Revision
- 137328
- Author
- [email protected]
- Date
- 2012-12-11 09:41:27 -0800 (Tue, 11 Dec 2012)
Log Message
CoreIPC: ArgumentEncoder should have an inline buffer.
<http://webkit.org/b/104622>
Reviewed by Anders Carlsson.
Add a 4K inline buffer to CoreIPC::ArgumentEncoder to avoid malloc/free churn.
It was dominating the transient allocations graph in Instruments.
* Platform/CoreIPC/ArgumentEncoder.cpp:
(CoreIPC::ArgumentEncoder::ArgumentEncoder):
(CoreIPC::ArgumentEncoder::grow):
* Platform/CoreIPC/ArgumentEncoder.h:
(CoreIPC::ArgumentEncoder::buffer):
(ArgumentEncoder):
(CoreIPC::ArgumentEncoder::usesInlineBuffer):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (137327 => 137328)
--- trunk/Source/WebKit2/ChangeLog 2012-12-11 17:38:28 UTC (rev 137327)
+++ trunk/Source/WebKit2/ChangeLog 2012-12-11 17:41:27 UTC (rev 137328)
@@ -1,3 +1,21 @@
+2012-12-11 Andreas Kling <[email protected]>
+
+ CoreIPC: ArgumentEncoder should have an inline buffer.
+ <http://webkit.org/b/104622>
+
+ Reviewed by Anders Carlsson.
+
+ Add a 4K inline buffer to CoreIPC::ArgumentEncoder to avoid malloc/free churn.
+ It was dominating the transient allocations graph in Instruments.
+
+ * Platform/CoreIPC/ArgumentEncoder.cpp:
+ (CoreIPC::ArgumentEncoder::ArgumentEncoder):
+ (CoreIPC::ArgumentEncoder::grow):
+ * Platform/CoreIPC/ArgumentEncoder.h:
+ (CoreIPC::ArgumentEncoder::buffer):
+ (ArgumentEncoder):
+ (CoreIPC::ArgumentEncoder::usesInlineBuffer):
+
2012-12-11 Mike West <[email protected]>
Web Inspector: ConsoleTypes should not expose MessageType - it should be private to inspector.
Modified: trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.cpp (137327 => 137328)
--- trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.cpp 2012-12-11 17:38:28 UTC (rev 137327)
+++ trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.cpp 2012-12-11 17:41:27 UTC (rev 137328)
@@ -39,9 +39,8 @@
ArgumentEncoder::ArgumentEncoder()
: m_buffer(0)
- , m_bufferPointer(0)
, m_bufferSize(0)
- , m_bufferCapacity(0)
+ , m_bufferCapacity(inlineBufferSize)
{
}
@@ -68,27 +67,31 @@
if (alignedSize + size > m_bufferCapacity) {
size_t newCapacity = std::max(alignedSize + size, std::max(static_cast<size_t>(32), m_bufferCapacity + m_bufferCapacity / 4 + 1));
- // Use system malloc / realloc instead of fastMalloc due to
- // fastMalloc using MADV_FREE_REUSABLE which doesn't work with
- // mach messages with OOL message and MACH_MSG_VIRTUAL_COPY.
- // System malloc also calls madvise(MADV_FREE_REUSABLE) but after first
- // checking via madvise(CAN_REUSE) that it will succeed. Should this
- // behavior change we'll need to revisit this.
- if (!m_buffer)
- m_buffer = static_cast<uint8_t*>(malloc(newCapacity));
- else
- m_buffer = static_cast<uint8_t*>(realloc(m_buffer, newCapacity));
- if (!m_buffer)
- CRASH();
+ if (newCapacity > inlineBufferSize) {
+ // Use system malloc / realloc instead of fastMalloc due to
+ // fastMalloc using MADV_FREE_REUSABLE which doesn't work with
+ // mach messages with OOL message and MACH_MSG_VIRTUAL_COPY.
+ // System malloc also calls madvise(MADV_FREE_REUSABLE) but after first
+ // checking via madvise(CAN_REUSE) that it will succeed. Should this
+ // behavior change we'll need to revisit this.
+ if (!m_buffer)
+ m_buffer = static_cast<uint8_t*>(malloc(newCapacity));
+ else
+ m_buffer = static_cast<uint8_t*>(realloc(m_buffer, newCapacity));
+ if (!m_buffer)
+ CRASH();
+
+ if (usesInlineBuffer())
+ memcpy(m_buffer, m_inlineBuffer, m_bufferCapacity);
+ }
+
m_bufferCapacity = newCapacity;
}
m_bufferSize = alignedSize + size;
- m_bufferPointer = m_buffer + alignedSize + size;
-
- return m_buffer + alignedSize;
+ return buffer() + alignedSize;
}
void ArgumentEncoder::encodeFixedLengthData(const uint8_t* data, size_t size, unsigned alignment)
Modified: trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.h (137327 => 137328)
--- trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.h 2012-12-11 17:38:28 UTC (rev 137327)
+++ trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.h 2012-12-11 17:41:27 UTC (rev 137328)
@@ -98,7 +98,7 @@
return *this;
}
- uint8_t* buffer() const { return m_buffer; }
+ uint8_t* buffer() { return usesInlineBuffer() ? m_inlineBuffer : m_buffer; }
size_t bufferSize() const { return m_bufferSize; }
void addAttachment(const Attachment&);
@@ -108,15 +108,18 @@
ArgumentEncoder();
private:
+ static const size_t inlineBufferSize = 4096;
+ bool usesInlineBuffer() const { return m_bufferCapacity <= inlineBufferSize; }
uint8_t* grow(unsigned alignment, size_t size);
uint8_t* m_buffer;
- uint8_t* m_bufferPointer;
size_t m_bufferSize;
size_t m_bufferCapacity;
Vector<Attachment> m_attachments;
+
+ uint8_t m_inlineBuffer[inlineBufferSize];
};
} // namespace CoreIPC
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes