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 moved

Legend:

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

    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
     
    1111 *    documentation and/or other materials provided with the distribution.
    1212 *
    13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
    1414 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1515 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
    1717 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1818 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     
    2424 */
    2525
    26 #include "JSCanvasPixelArray.h"
     26#include "config.h"
     27#include "ByteArray.h"
    2728
    28 #include "CanvasPixelArray.h"
     29namespace JSC {
    2930
    30 using namespace JSC;
     31PassRefPtr<ByteArray> ByteArray::create(size_t size)
     32{
     33    unsigned char* buffer = new unsigned char[size + sizeof(ByteArray)];
     34    ASSERT((reinterpret_cast<size_t>(buffer) & 3) == 0);
     35    return adoptRef(new (buffer) ByteArray(size));
     36}
    3137
    32 namespace WebCore {
    33    
    34     inline JSValue* JSCanvasPixelArray::getByIndex(ExecState*, unsigned index)
    35     {
    36         unsigned char result;
    37         if (!impl()->get(index, result))
    38             return jsUndefined();
    39         return JSImmediate::from(result);
    40     }
    41    
    42     inline void JSCanvasPixelArray::indexSetter(ExecState* exec, unsigned index, JSValue* value)
    43     {
    44         double pixelValue = value->toNumber(exec);
    45         if (exec->hadException())
    46             return;
    47         m_impl->set(index, pixelValue);
    48     }
    49    
    50 } // namespace WebCore
     38}
Note: See TracChangeset for help on using the changeset viewer.