exponentially grow the read buffer size for the html resource
authorJie Chen <jie.a.chen@intel.com>
Mon, 15 Apr 2013 01:41:58 +0000 (09:41 +0800)
committerGerrit Code Review <gerrit2@kim11>
Tue, 7 May 2013 04:08:39 +0000 (13:08 +0900)
[Title] exponentially grow the read buffer size for the html resource
[Issue] N/A
[Problem] takes long time to entirely load and render some huge pages like Facebook
[Cause] The page early rendering with partially loading is an attractive feature
for better UX. The rendering and loading tasks are performed in turn in
same event loop of the WebProcess. After the loading task parses each
newly loaded buffer of html or css content, the new dom nodes and css
rules will be added. Later, the rendering task will recompute the render
tree accordingly. Enlarging the buffer size can reduce this recomputing
to some extent. Hypothetically it can be totally avoided if the buffer
size is large enough to completely accommodate all the html with merely one buffer.
[Solution] exponentially grow the read buffer size for the html resource

Change-Id: I6fbf7c1a66876f64a40b956cf7e5b3c06d0d6068

Source/WTF/wtf/Platform.h
Source/WebCore/platform/network/ResourceHandleInternal.h
Source/WebCore/platform/network/soup/tizen/ResourceHandleSoupTizen.cpp

index 538ba03..968ed6f 100644 (file)
 
 #define ENABLE_TIZEN_PAUSE_NETWORK 1 /* Gyuyoung Kim(gyuyoung.kim@samsung.com) : */
 #define ENABLE_TIZEN_HTTP_REQUEST_HEADER_APPEND 1 /* Kwangtae Ko(kwangtae.ko@samsung.com : Append request headers for  accept-charset and x-wap-proxy-cookie */
+#define ENABLE_TIZEN_EXPONENTIAL_BUFFER_SIZE 1 /* Jie Chen(jie.a.chen@intel.com) */
 
 /* Workaround Patches */
 #define ENABLE_TIZEN_PREVENT_INCREMENTAL_IMAGE_RENDERING_WORKAROUND 1 /* Ryuan Choi(ryuan.choi@samsung.com) : */
index e5bd0c1..a8a895c 100644 (file)
@@ -109,6 +109,9 @@ namespace WebCore {
 #if USE(SOUP)
             , m_cancelled(false)
             , m_buffer(0)
+#if ENABLE(TIZEN_EXPONENTIAL_BUFFER_SIZE)
+            , m_bufferSize(0)
+#endif
             , m_bodySize(0)
             , m_bodyDataSent(0)
 #endif
@@ -194,6 +197,9 @@ namespace WebCore {
         GRefPtr<GAsyncResult> m_deferredResult;
         GRefPtr<GSource> m_timeoutSource;
         char* m_buffer;
+#if ENABLE(TIZEN_EXPONENTIAL_BUFFER_SIZE)
+        unsigned long m_bufferSize;
+#endif
         unsigned long m_bodySize;
         unsigned long m_bodyDataSent;
         RefPtr<NetworkingContext> m_context;
index 5f3454c..0b8519e 100755 (executable)
 #include <sys/time.h>
 #endif
 
-namespace WebCore {
 
+namespace WebCore {
+#if ENABLE(TIZEN_EXPONENTIAL_BUFFER_SIZE)
+#define READ_BUFFER_SIZE_MIN (8*1024)
+#define READ_BUFFER_SIZE_MAX (64*1024)
+#else
 #define READ_BUFFER_SIZE 8192
+#endif
 
 // Use the same value as in NSURLError.h
 static const int gTimeoutError = -1001;
@@ -505,7 +510,11 @@ static void cleanupSoupRequestOperation(ResourceHandle* handle, bool isDestroyin
     }
 
     if (d->m_buffer) {
+#if ENABLE(TIZEN_EXPONENTIAL_BUFFER_SIZE)
+        g_slice_free1(d->m_bufferSize, d->m_buffer);
+#else
         g_slice_free1(READ_BUFFER_SIZE, d->m_buffer);
+#endif
         d->m_buffer = 0;
     }
 
@@ -600,8 +609,12 @@ static void sendRequestCallback(GObject* source, GAsyncResult* res, gpointer dat
 #endif
 
     d->m_inputStream = adoptGRef(in);
+#if ENABLE(TIZEN_EXPONENTIAL_BUFFER_SIZE)
+    d->m_buffer = static_cast<char*>(g_slice_alloc(READ_BUFFER_SIZE_MIN));
+    d->m_bufferSize = READ_BUFFER_SIZE_MIN;
+#else
     d->m_buffer = static_cast<char*>(g_slice_alloc(READ_BUFFER_SIZE));
-
+#endif
     if (soupMessage) {
         if (handle->shouldContentSniff() && soupMessage->status_code != SOUP_STATUS_NOT_MODIFIED) {
             const char* sniffedType = soup_request_get_content_type(d->m_soupRequest.get());
@@ -622,9 +635,13 @@ static void sendRequestCallback(GObject* source, GAsyncResult* res, gpointer dat
         cleanupSoupRequestOperation(handle.get());
         return;
     }
-
-    g_input_stream_read_async(d->m_inputStream.get(), d->m_buffer, READ_BUFFER_SIZE,
+#if ENABLE(TIZEN_EXPONENTIAL_BUFFER_SIZE)
+    g_input_stream_read_async(d->m_inputStream.get(), d->m_buffer, d->m_bufferSize,
                               G_PRIORITY_DEFAULT, d->m_cancellable.get(), readCallback, handle.get());
+#else
+    g_input_stream_read_async(d->m_inputStream.get(), d->m_buffer, READ_BUFFER_SIZE,
+                               G_PRIORITY_DEFAULT, d->m_cancellable.get(), readCallback, handle.get());
+#endif
 }
 
 #if ENABLE(TIZEN_ON_AUTHENTICATION_REQUESTED)
@@ -1271,8 +1288,23 @@ static void readCallback(GObject* source, GAsyncResult* asyncResult, gpointer da
 #if ENABLE(TIZEN_LOG)
     LOG(Network,"[Network] ResourceHandleSoup readCallback : Invoke g_input_stream_read_async \n");
 #endif
-    g_input_stream_read_async(d->m_inputStream.get(), d->m_buffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT,
+
+#if ENABLE(TIZEN_EXPONENTIAL_BUFFER_SIZE)
+    if (equalIgnoringCase(d->m_response.mimeType(), "text/html")
+        && d->m_bufferSize < READ_BUFFER_SIZE_MAX && bytesRead == d->m_bufferSize) {
+
+        g_slice_free1(d->m_bufferSize, d->m_buffer);
+        d->m_buffer = 0;
+        d->m_bufferSize *= 2;
+        d->m_buffer = static_cast<char*>(g_slice_alloc(d->m_bufferSize));
+    }
+    g_input_stream_read_async(d->m_inputStream.get(), d->m_buffer, d->m_bufferSize, G_PRIORITY_DEFAULT,
                               d->m_cancellable.get(), readCallback, handle.get());
+#else
+    g_input_stream_read_async(d->m_inputStream.get(), d->m_buffer, READ_BUFFER_SIZE, G_PRIORITY_DEFAULT,
+                               d->m_cancellable.get(), readCallback, handle.get());
+#endif
+
 }
 
 static gboolean requestTimeoutCallback(gpointer data)