Bug 120813 - Use of Uint8ClampedArray makes filters twice as slow
Summary: Use of Uint8ClampedArray makes filters twice as slow
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-09-05 17:07 PDT by Simon Fraser (smfr)
Modified: 2022-12-30 16:39 PST (History)
7 users (show)

See Also:


Attachments
Testcase (872 bytes, text/html)
2013-09-05 17:08 PDT, Simon Fraser (smfr)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2013-09-05 17:07:50 PDT
I was curious about why blur filters on image backgrounds are incredibly slow. Sampling shows lots of time in GenericTypedArrayView::set(unsigned index, double value) const which is doing a safe double -> int cast with clamping.

This comes out of a tight look in the blurring code:

                for (int x = 0; x < effectWidth; ++x) {
                    int pixelByteOffset = line + x * stride + channel;
                    dstPixelArray->set(pixelByteOffset, static_cast<unsigned char>(sum / dx));

It's crazy that we're wasting time doing double -> int conversion when the caller is passing in an unsigned char. We're converting double -> unsigned char -> double -> int32_t -> uint8_t

Bypassing this crap by just filling a uint8_t[] and using dstPixelArray->setRange() makes blurring twice as fast.
Comment 1 Simon Fraser (smfr) 2013-09-05 17:08:10 PDT
Created attachment 210684 [details]
Testcase
Comment 2 Radar WebKit Bug Importer 2013-09-06 11:08:52 PDT
<rdar://problem/14930799>
Comment 3 Adenilson Cavalcanti Silva 2014-02-28 11:34:49 PST
Started looking into this.
Comment 4 Ahmad Saleem 2022-12-30 16:39:31 PST
It is still taking several steps to blur completely in Safari 16.2 & STP160 but this does not seem to be working in Chrome Canary 111 and Firefox Nightly 110 for some reasons even after modifying to change pic URL to HTTPS and removing -webkit- prefix in following:

URL - https://jsfiddle.net/unz3h758/2/show