Commit f20f9a30 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[ScriptStreaming] Stream small scripts when ScheduledScriptStreaming is enabled.

With scheduled script streaming and background compilation it is now worthwhile to
stream smaller scripts. Enable support for streaming these smaller scripts when
the ScheduledScriptStreaming trial is enabled to investigate performance impact.

BUG=chromium:865098

Change-Id: Ia7691dbe9f8dd970aafda2715a34edc3ef16616b
Reviewed-on: https://chromium-review.googlesource.com/1160653Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580466}
parent aebf4afa
...@@ -321,6 +321,16 @@ static void RunScriptStreamingTask( ...@@ -321,6 +321,16 @@ static void RunScriptStreamingTask(
streamer->StreamingCompleteOnBackgroundThread(); streamer->StreamingCompleteOnBackgroundThread();
} }
bool ScriptStreamer::HasEnoughDataForStreaming(size_t resource_buffer_size) {
if (RuntimeEnabledFeatures::ScheduledScriptStreamingEnabled()) {
// Enable streaming for small scripts, but we must still check the BOM
// before starting streaming.
return resource_buffer_size >= kMaximumLengthOfBOM;
}
// Only stream larger scripts.
return resource_buffer_size >= small_script_threshold_;
}
void ScriptStreamer::NotifyAppendData(ScriptResource* resource) { void ScriptStreamer::NotifyAppendData(ScriptResource* resource) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
if (streaming_suppressed_) if (streaming_suppressed_)
...@@ -330,14 +340,13 @@ void ScriptStreamer::NotifyAppendData(ScriptResource* resource) { ...@@ -330,14 +340,13 @@ void ScriptStreamer::NotifyAppendData(ScriptResource* resource) {
// enough - wait until the next data chunk comes before deciding whether // enough - wait until the next data chunk comes before deciding whether
// to start the streaming. // to start the streaming.
DCHECK(resource->ResourceBuffer()); DCHECK(resource->ResourceBuffer());
if (resource->ResourceBuffer()->size() < small_script_threshold_) if (!HasEnoughDataForStreaming(resource->ResourceBuffer()->size()))
return; return;
have_enough_data_for_streaming_ = true; have_enough_data_for_streaming_ = true;
{ {
// Check for BOM (byte order marks), because that might change our // Check for BOM (byte order marks), because that might change our
// understanding of the data encoding. // understanding of the data encoding.
constexpr size_t kMaximumLengthOfBOM = 4;
char maybe_bom[kMaximumLengthOfBOM] = {}; char maybe_bom[kMaximumLengthOfBOM] = {};
if (!resource->ResourceBuffer()->GetBytes(maybe_bom, if (!resource->ResourceBuffer()->GetBytes(maybe_bom,
kMaximumLengthOfBOM)) { kMaximumLengthOfBOM)) {
......
...@@ -120,6 +120,8 @@ class CORE_EXPORT ScriptStreamer final ...@@ -120,6 +120,8 @@ class CORE_EXPORT ScriptStreamer final
// Scripts whose first data chunk is smaller than this constant won't be // Scripts whose first data chunk is smaller than this constant won't be
// streamed. Non-const for testing. // streamed. Non-const for testing.
static size_t small_script_threshold_; static size_t small_script_threshold_;
// Maximum size of the BOM marker.
static constexpr size_t kMaximumLengthOfBOM = 4;
ScriptStreamer(ClassicPendingScript*, ScriptStreamer(ClassicPendingScript*,
ScriptState*, ScriptState*,
...@@ -128,6 +130,7 @@ class CORE_EXPORT ScriptStreamer final ...@@ -128,6 +130,7 @@ class CORE_EXPORT ScriptStreamer final
void StreamingComplete(); void StreamingComplete();
void NotifyFinishedToClient(); void NotifyFinishedToClient();
bool HasEnoughDataForStreaming(size_t resource_buffer_size);
Member<ClassicPendingScript> pending_script_; Member<ClassicPendingScript> pending_script_;
// Whether ScriptStreamer is detached from the Resource. In those cases, the // Whether ScriptStreamer is detached from the Resource. In those cases, the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment