Ignore:
Timestamp:
Jan 5, 2009, 3:57:09 PM (16 years ago)
Author:
[email protected]
Message:

CanvasPixelArray performance is too slow
<https://bugs.webkit.org/show_bug.cgi?id=23123>

Reviewed by Gavin Barraclough

JavaScriptCore:
The fix to this is to devirtualise get and put in a manner similar to
JSString and JSArray. To do this I've added a ByteArray implementation
and JSByteArray wrapper to JSC. We can then do vptr comparisons to
devirtualise the calls.

This devirtualisation improves performance by 1.5-2x in my somewhat ad
hoc tests.

WebCore:
Remove the WebCore CanvasPixelArray implementation and replace
CPA usage with JSC::ByteArray. Replace the JSCanvasPixelArray
wrapper with an explicitly instantiated JSByteArray put on the
JSImageData object as an ordinary ReadOnly, DontDelete property.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/ByteArray.h

    r39624 r39625  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2009 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #include "config.h"
    27 #include "JSImageData.h"
     26#ifndef ByteArray_h
     27#define ByteArray_h
    2828
    29 #include "ImageData.h"
    30 using namespace JSC;
     29#include "wtf/PassRefPtr.h"
     30#include "wtf/RefCounted.h"
    3131
    32 namespace WebCore {
     32namespace JSC {
     33    class ByteArray : public RefCounted<ByteArray> {
     34    public:
     35        unsigned length() const { return m_size; }
    3336
    34 JSValue* toJS(ExecState* exec, ImageData* imageData)
    35 {
    36     if (!imageData)
    37         return jsNull();
    38    
    39     DOMObject* wrapper = getCachedDOMObjectWrapper(exec->globalData(), imageData);
    40     if (wrapper)
    41         return wrapper;
    42    
    43     wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, ImageData, imageData);
    44    
    45     exec->heap()->reportExtraMemoryCost(imageData->data()->length());
    46    
    47     return wrapper;
     37        void set(unsigned index, double value)
     38        {
     39            if (index >= m_size)
     40                return;
     41            if (!(value > 0)) // Clamp NaN to 0
     42                value = 0;
     43            else if (value > 255)
     44                value = 255;
     45            m_data[index] = static_cast<unsigned char>(value + 0.5);
     46        }
     47
     48        bool get(unsigned index, unsigned char& result) const
     49        {
     50            if (index >= m_size)
     51                return false;
     52            result = m_data[index];
     53            return true;
     54        }
     55
     56        unsigned char* data() { return m_data; }
     57
     58        static PassRefPtr<ByteArray> create(size_t size);
     59
     60    private:
     61        ByteArray(size_t size)
     62            : m_size(size)
     63        {
     64        }
     65        size_t m_size;
     66        unsigned char m_data[0];
     67    };
    4868}
    4969
    50 }
     70#endif
Note: See TracChangeset for help on using the changeset viewer.