Changeset 137328 in webkit


Ignore:
Timestamp:
Dec 11, 2012 9:41:27 AM (11 years ago)
Author:
akling@apple.com
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):

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r137318 r137328  
     12012-12-11  Andreas Kling  <akling@apple.com>
     2
     3        CoreIPC: ArgumentEncoder should have an inline buffer.
     4        <http://webkit.org/b/104622>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Add a 4K inline buffer to CoreIPC::ArgumentEncoder to avoid malloc/free churn.
     9        It was dominating the transient allocations graph in Instruments.
     10
     11        * Platform/CoreIPC/ArgumentEncoder.cpp:
     12        (CoreIPC::ArgumentEncoder::ArgumentEncoder):
     13        (CoreIPC::ArgumentEncoder::grow):
     14        * Platform/CoreIPC/ArgumentEncoder.h:
     15        (CoreIPC::ArgumentEncoder::buffer):
     16        (ArgumentEncoder):
     17        (CoreIPC::ArgumentEncoder::usesInlineBuffer):
     18
    1192012-12-11  Mike West  <mkwst@chromium.org>
    220
  • trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.cpp

    r131990 r137328  
    4040ArgumentEncoder::ArgumentEncoder()
    4141    : m_buffer(0)
    42     , m_bufferPointer(0)
    4342    , m_bufferSize(0)
    44     , m_bufferCapacity(0)
     43    , m_bufferCapacity(inlineBufferSize)
    4544{
    4645}
     
    6968    if (alignedSize + size > m_bufferCapacity) {
    7069        size_t newCapacity = std::max(alignedSize + size, std::max(static_cast<size_t>(32), m_bufferCapacity + m_bufferCapacity / 4 + 1));
    71         // Use system malloc / realloc instead of fastMalloc due to
    72         // fastMalloc using MADV_FREE_REUSABLE which doesn't work with
    73         // mach messages with OOL message and MACH_MSG_VIRTUAL_COPY.
    74         // System malloc also calls madvise(MADV_FREE_REUSABLE) but after first
    75         // checking via madvise(CAN_REUSE) that it will succeed. Should this
    76         // behavior change we'll need to revisit this.
    77         if (!m_buffer)
    78             m_buffer = static_cast<uint8_t*>(malloc(newCapacity));
    79         else
    80             m_buffer = static_cast<uint8_t*>(realloc(m_buffer, newCapacity));
    8170
    82         if (!m_buffer)
    83             CRASH();
     71        if (newCapacity > inlineBufferSize) {
     72            // Use system malloc / realloc instead of fastMalloc due to
     73            // fastMalloc using MADV_FREE_REUSABLE which doesn't work with
     74            // mach messages with OOL message and MACH_MSG_VIRTUAL_COPY.
     75            // System malloc also calls madvise(MADV_FREE_REUSABLE) but after first
     76            // checking via madvise(CAN_REUSE) that it will succeed. Should this
     77            // behavior change we'll need to revisit this.
     78            if (!m_buffer)
     79                m_buffer = static_cast<uint8_t*>(malloc(newCapacity));
     80            else
     81                m_buffer = static_cast<uint8_t*>(realloc(m_buffer, newCapacity));
     82
     83            if (!m_buffer)
     84                CRASH();
     85
     86            if (usesInlineBuffer())
     87                memcpy(m_buffer, m_inlineBuffer, m_bufferCapacity);
     88        }
    8489
    8590        m_bufferCapacity = newCapacity;       
     
    8792
    8893    m_bufferSize = alignedSize + size;
    89     m_bufferPointer = m_buffer + alignedSize + size;
    90    
    91     return m_buffer + alignedSize;
     94    return buffer() + alignedSize;
    9295}
    9396
  • trunk/Source/WebKit2/Platform/CoreIPC/ArgumentEncoder.h

    r132169 r137328  
    9999    }
    100100
    101     uint8_t* buffer() const { return m_buffer; }
     101    uint8_t* buffer() { return usesInlineBuffer() ? m_inlineBuffer : m_buffer; }
    102102    size_t bufferSize() const { return m_bufferSize; }
    103103
     
    109109
    110110private:
     111    static const size_t inlineBufferSize = 4096;
     112    bool usesInlineBuffer() const { return m_bufferCapacity <= inlineBufferSize; }
    111113    uint8_t* grow(unsigned alignment, size_t size);
    112114   
    113115    uint8_t* m_buffer;
    114     uint8_t* m_bufferPointer;
    115116   
    116117    size_t m_bufferSize;
     
    118119
    119120    Vector<Attachment> m_attachments;
     121
     122    uint8_t m_inlineBuffer[inlineBufferSize];
    120123};
    121124
Note: See TracChangeset for help on using the changeset viewer.