Bug 26307

Summary: REGRESSION: Safari hangs while trying to edit the HTML source in sites rich text editor
Product: WebKit Reporter: Venkat Karun <vkarun>
Component: New BugsAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: eric, jparent, ojan
Priority: P1    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
shark sample none

Description Venkat Karun 2009-06-10 17:22:14 PDT
1. Edit any google sites page 
2. Click on the "edit html source" button in the toolbar

Expected result:

A tabbed dialog with HTML and preview tabs pops up without making the browser unresponsive.

Actual result:

The dialog appears but the browser stays unresponsive for about 15-20
seconds.

Additional information:
We were able to verify that this happened while installing CSS styles programatically in the preview iframe but couldn't reproduce this with a reduced case.
Comment 1 Ojan Vafai 2009-06-10 17:31:16 PDT
Created attachment 31148 [details]
shark sample

This is a 30 second shark sample from my Debug ToT build (synced to r44594).
Comment 2 Venkat Karun 2009-06-10 18:21:56 PDT
Please note that this doesn't happen with Safari 4 public beta (528.16) 
Comment 3 Julie Parent 2009-06-10 18:35:28 PDT
But it does happen in the Safari 4.0 final release: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17
Comment 4 Julie Parent 2009-06-10 18:36:04 PDT
Marking as P1 since this is a regression.
Comment 6 Venkat Karun 2009-06-12 10:28:35 PDT
Just adding some metrics from tests that I performed by dividing the set of all CSS rulesets applied to the preview iframe into individual buckets. Each bucket corresponds to a 'style' element. These tests were performed on safari 4 (latest webkit nightly)

Total ruleset size:- 3374

Number of buckets  Time taken to install styles (ms)
1                             4385
2                             1839
4                             1267
8                              767
16                            370
32                            274
Comment 7 Venkat Karun 2009-06-16 14:50:31 PDT
We have a temporary workaround in place for this. Our previous code path revolved around creating a style element, appending the style element to the head and then setting styles in the content element. We swapped the order of the last two steps and this seemed to resolve this.

From:
var styleSheet = doc.createElement('style')
head.appendChild(styleSheet);
styleSheet.innerText = stylesString;

To:
var styleSheet = doc.createElement('style')
styleSheet.innerText = stylesString;
head.appendChild(styleSheet);