Bug 57269 - REGRESSION (r82151): Every WKView paint now makes an extra copy of the painted bits
Summary: REGRESSION (r82151): Every WKView paint now makes an extra copy of the painte...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows 7
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar, PlatformOnly, Regression
Depends on:
Blocks:
 
Reported: 2011-03-28 14:37 PDT by Adam Roben (:aroben)
Modified: 2011-05-04 09:58 PDT (History)
5 users (show)

See Also:


Attachments
Patch for performance testing (5.91 KB, patch)
2011-04-07 08:31 PDT, Adam Roben (:aroben)
no flags Details | Formatted Diff | Diff
Make ShareableBitmap::makeCGImageCopy use a copy-on-write copy on Windows when possible (11.15 KB, patch)
2011-05-04 09:51 PDT, Adam Roben (:aroben)
andersca: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Roben (:aroben) 2011-03-28 14:37:48 PDT
r82151 changed ShareableBitmap::paint to use CGBitmapContextCreateImage in its implementation, rather than creating an image using a custom data provider. On Mac, CGBitmapContextCreateImage uses a copy-on-write implementation, but on Windows it just copies the data. This means that we're now making an extra copy of every pixel that we paint into a WKView.

This is likely a performance regression, though that has not been confirmed.
Comment 1 Adam Roben (:aroben) 2011-03-28 14:38:28 PDT
<rdar://problem/9198788>
Comment 2 Adam Roben (:aroben) 2011-04-07 07:45:24 PDT
It has now been confirmed that r82151 is a performance regression. Once upon a time we had a policy of rolling out performance regressions. I guess that's no longer the policy.
Comment 3 Adam Roben (:aroben) 2011-04-07 08:31:13 PDT
Created attachment 88643 [details]
Patch for performance testing

Here's a patch that should get rid of the extra copy. I haven't performance tested it, though.
Comment 4 Steve Falkenburg 2011-04-07 10:20:53 PDT
This patch is a 5% speed-up on iBench HTML cached.
Comment 5 Adam Roben (:aroben) 2011-04-07 14:52:08 PDT
Comment on attachment 88643 [details]
Patch for performance testing

I don't think this patch is safe. If someone modifies the ShareableBitmap after the CGImageRef has been made but before the newMapping has been written into, the newMapping will see the modifications. This is exactly what we're trying to avoid. (And since newMapping should never be written into, we're basically never safe.)

This is just how copy-on-write views work in Windows. If I have two views of the same mapping, A and B, and A has FILE_MAP_WRITE and B has FILE_MAP_COPY, B will see writes to A until B is written into. From then on B will be operating on its own copy that is insulated from A.
Comment 6 Adam Roben (:aroben) 2011-05-02 14:27:46 PDT
(In reply to comment #5)
> (From update of attachment 88643 [details])
> I don't think this patch is safe. If someone modifies the ShareableBitmap after the CGImageRef has been made but before the newMapping has been written into, the newMapping will see the modifications. This is exactly what we're trying to avoid. (And since newMapping should never be written into, we're basically never safe.)
> 
> This is just how copy-on-write views work in Windows. If I have two views of the same mapping, A and B, and A has FILE_MAP_WRITE and B has FILE_MAP_COPY, B will see writes to A until B is written into. From then on B will be operating on its own copy that is insulated from A.

I guess we could use A for the CGImageRef and use B for the ShareableBitmap from then on. The CGImageRef can't be written to, so that should work.
Comment 7 Adam Roben (:aroben) 2011-05-04 08:43:10 PDT
(In reply to comment #6)
> (In reply to comment #5)
> > (From update of attachment 88643 [details] [details])
> > I don't think this patch is safe. If someone modifies the ShareableBitmap after the CGImageRef has been made but before the newMapping has been written into, the newMapping will see the modifications. This is exactly what we're trying to avoid. (And since newMapping should never be written into, we're basically never safe.)
> > 
> > This is just how copy-on-write views work in Windows. If I have two views of the same mapping, A and B, and A has FILE_MAP_WRITE and B has FILE_MAP_COPY, B will see writes to A until B is written into. From then on B will be operating on its own copy that is insulated from A.
> 
> I guess we could use A for the CGImageRef and use B for the ShareableBitmap from then on. The CGImageRef can't be written to, so that should work.

Trying this out now.
Comment 8 Adam Roben (:aroben) 2011-05-04 09:51:28 PDT
Created attachment 92261 [details]
Make ShareableBitmap::makeCGImageCopy use a copy-on-write copy on Windows when possible
Comment 9 Adam Roben (:aroben) 2011-05-04 09:58:45 PDT
Committed r85754: <http://trac.webkit.org/changeset/85754>