[compile hints] Enable testing both compile hints modes simultaneously
The two possible feature implementations are "follow the magic comment always" and "follow the magic comment only when producing the code cache". This CL allows selecting the mode via a runtime enabled feature. Drive-by fix 1: There was an unimplemented code path related to modules and setting the runtime enabled flag. Fixed it in this CL. Drive-by fix 2: module_record.cc was passing the params wrong when calling V8CodeCache::GetCompileOptions. Bug: 42203853 Change-Id: I4ad956bf2b257fac1e152d04add89340e773c412 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5953340 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/main@{#1379626}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
bc66e81a70
commit
ed20fd4849
gin
third_party/blink/renderer
@ -282,11 +282,6 @@ BASE_FEATURE(kV8IntelJCCErratumMitigation,
|
||||
|
||||
// JavaScript language features.
|
||||
|
||||
// Enables the experiment with compile hints as magic comments.
|
||||
BASE_FEATURE(kJavaScriptCompileHintsMagic,
|
||||
("JavaScriptCompileHintsMagic"),
|
||||
kFeatureDefaultStateControlledByV8);
|
||||
|
||||
// Enables the iterator helpers proposal.
|
||||
BASE_FEATURE(kJavaScriptIteratorHelpers,
|
||||
("kJavaScriptIteratorHelpers"),
|
||||
|
@ -87,7 +87,6 @@ GIN_EXPORT BASE_DECLARE_FEATURE(kV8UseLibmTrigFunctions);
|
||||
GIN_EXPORT BASE_DECLARE_FEATURE(kV8UseOriginalMessageForStackTrace);
|
||||
GIN_EXPORT extern const base::FeatureParam<base::TimeDelta>
|
||||
kV8MemoryReducerStartDelay;
|
||||
GIN_EXPORT BASE_DECLARE_FEATURE(kJavaScriptCompileHintsMagic);
|
||||
GIN_EXPORT BASE_DECLARE_FEATURE(kJavaScriptIteratorHelpers);
|
||||
GIN_EXPORT BASE_DECLARE_FEATURE(kJavaScriptPromiseWithResolvers);
|
||||
GIN_EXPORT BASE_DECLARE_FEATURE(kJavaScriptRegExpModifiers);
|
||||
|
@ -3,12 +3,14 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "third_party/blink/renderer/bindings/core/v8/module_record.h"
|
||||
|
||||
#include "base/feature_list.h"
|
||||
#include "third_party/blink/public/common/features.h"
|
||||
#include "third_party/blink/public/mojom/v8_cache_options.mojom-blink.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/boxed_v8_module.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_common.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_script_runner.h"
|
||||
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
|
||||
#include "third_party/blink/renderer/core/probe/core_probes.h"
|
||||
@ -76,15 +78,14 @@ v8::Local<v8::Module> ModuleRecord::Compile(
|
||||
}
|
||||
// TODO(chromium:1406506): Add a compile hints solution for module records.
|
||||
constexpr bool kMightGenerateCompileHints = false;
|
||||
const bool v8_compile_hints_magic_comment_runtime_enabled =
|
||||
RuntimeEnabledFeatures::JavaScriptCompileHintsMagicRuntimeEnabled(
|
||||
execution_context);
|
||||
constexpr bool kCanUseCrowdsourcedCompileHints = false;
|
||||
std::tie(compile_options, produce_cache_options, no_cache_reason) =
|
||||
V8CodeCache::GetCompileOptions(
|
||||
v8_cache_options, params.CacheHandler(),
|
||||
params.GetSourceText().length(), params.SourceLocationType(),
|
||||
params.BaseURL(), kMightGenerateCompileHints,
|
||||
v8_compile_hints_magic_comment_runtime_enabled);
|
||||
kCanUseCrowdsourcedCompileHints,
|
||||
v8_compile_hints::GetMagicCommentMode(execution_context));
|
||||
|
||||
if (!V8ScriptRunner::CompileModule(
|
||||
isolate, params, text_position, compile_options, no_cache_reason,
|
||||
|
@ -684,8 +684,7 @@ bool ResourceScriptStreamer::TryStartStreamingTask() {
|
||||
script_resource_->GetV8CrowdsourcedCompileHintsProducer(),
|
||||
script_resource_->GetV8CrowdsourcedCompileHintsConsumer(),
|
||||
script_resource_->Url(),
|
||||
script_resource_
|
||||
->GetV8CompileHintsMagicCommentRuntimeFeatureEnabled())
|
||||
script_resource_->GetV8CompileHintsMagicCommentMode())
|
||||
.Build((V8CodeCache::HasCompileHints(
|
||||
script_resource_->CacheHandler(),
|
||||
CachedMetadataHandler::kAllowUnchecked) &&
|
||||
@ -1308,8 +1307,7 @@ class BackgroundResourceScriptStreamer::BackgroundProcessorFactory final
|
||||
script_resource->GetV8CrowdsourcedCompileHintsProducer(),
|
||||
script_resource->GetV8CrowdsourcedCompileHintsConsumer(),
|
||||
script_resource->Url(),
|
||||
script_resource
|
||||
->GetV8CompileHintsMagicCommentRuntimeFeatureEnabled())),
|
||||
script_resource->GetV8CompileHintsMagicCommentMode())),
|
||||
streamer_handle_(std::move(streamer_handle)) {}
|
||||
BackgroundProcessorFactory(const BackgroundProcessorFactory&) = delete;
|
||||
BackgroundProcessorFactory& operator=(const BackgroundProcessorFactory&) =
|
||||
|
@ -214,11 +214,10 @@ class ScriptStreamingTest : public testing::Test {
|
||||
kNoCompileHintsProducer = nullptr;
|
||||
constexpr v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
kNoCompileHintsConsumer = nullptr;
|
||||
constexpr bool kNoV8CompileHintsMagicCommentRuntimeEnabled = false;
|
||||
resource_ = ScriptResource::Fetch(
|
||||
params, fetcher, resource_client_, isolate,
|
||||
ScriptResource::kAllowStreaming, kNoCompileHintsProducer,
|
||||
kNoCompileHintsConsumer, kNoV8CompileHintsMagicCommentRuntimeEnabled);
|
||||
kNoCompileHintsConsumer, v8_compile_hints::MagicCommentMode::kNever);
|
||||
resource_->AddClient(resource_client_, task_runner.get());
|
||||
|
||||
ResourceResponse response(url_);
|
||||
@ -1026,11 +1025,10 @@ class BackgroundResourceScriptStreamerTest : public testing::Test {
|
||||
}
|
||||
constexpr v8_compile_hints::V8CrowdsourcedCompileHintsProducer*
|
||||
kNoCompileHintsProducer = nullptr;
|
||||
constexpr bool kNoV8CompileHintsMagicCommentRuntimeEnabled = false;
|
||||
resource_ = ScriptResource::Fetch(
|
||||
params, fetcher, resource_client_, isolate,
|
||||
ScriptResource::kAllowStreaming, kNoCompileHintsProducer,
|
||||
v8_compile_hints_consumer, kNoV8CompileHintsMagicCommentRuntimeEnabled);
|
||||
v8_compile_hints_consumer, v8_compile_hints::MagicCommentMode::kNever);
|
||||
resource_->AddClient(resource_client_, main_thread_task_runner.get());
|
||||
|
||||
CHECK(dummy_loader_factory->load_started());
|
||||
|
@ -262,6 +262,53 @@ scoped_refptr<CachedMetadata> V8CodeCache::GetCachedMetadataForCompileHints(
|
||||
return cached_metadata;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool CanAddCompileHintsMagicToCompileOption(
|
||||
v8::ScriptCompiler::CompileOptions compile_options) {
|
||||
// Adding compile hints to kConsumeCodeCache or kEagerCompile doesn't make
|
||||
// sense. kProduceCompileHints and kConsumeCompileHints can be combined with
|
||||
// kFollowCompileHintsMagicComment, since they still affect scripts which
|
||||
// don't have the magic comment.
|
||||
|
||||
// This fails if new compile options are added.
|
||||
DCHECK((compile_options &
|
||||
~(v8::ScriptCompiler::CompileOptions::kConsumeCodeCache |
|
||||
v8::ScriptCompiler::CompileOptions::kEagerCompile |
|
||||
v8::ScriptCompiler::CompileOptions::kProduceCompileHints |
|
||||
v8::ScriptCompiler::CompileOptions::kConsumeCompileHints)) == 0);
|
||||
|
||||
return (compile_options &
|
||||
(v8::ScriptCompiler::CompileOptions::kConsumeCodeCache |
|
||||
v8::ScriptCompiler::CompileOptions::kEagerCompile)) == 0;
|
||||
}
|
||||
|
||||
std::tuple<v8::ScriptCompiler::CompileOptions,
|
||||
V8CodeCache::ProduceCacheOptions,
|
||||
v8::ScriptCompiler::NoCacheReason>
|
||||
MaybeAddCompileHintsMagic(
|
||||
std::tuple<v8::ScriptCompiler::CompileOptions,
|
||||
V8CodeCache::ProduceCacheOptions,
|
||||
v8::ScriptCompiler::NoCacheReason> input,
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode) {
|
||||
auto [compile_options, produce_cache_options, no_cache_reason] = input;
|
||||
if (CanAddCompileHintsMagicToCompileOption(compile_options) &&
|
||||
(magic_comment_mode == v8_compile_hints::MagicCommentMode::kAlways ||
|
||||
(magic_comment_mode ==
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache &&
|
||||
produce_cache_options ==
|
||||
V8CodeCache::ProduceCacheOptions::kProduceCodeCache))) {
|
||||
return std::make_tuple(
|
||||
v8::ScriptCompiler::CompileOptions(
|
||||
compile_options |
|
||||
v8::ScriptCompiler::kFollowCompileHintsMagicComment),
|
||||
produce_cache_options, no_cache_reason);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::tuple<v8::ScriptCompiler::CompileOptions,
|
||||
V8CodeCache::ProduceCacheOptions,
|
||||
v8::ScriptCompiler::NoCacheReason>
|
||||
@ -270,28 +317,17 @@ V8CodeCache::GetCompileOptions(
|
||||
const ClassicScript& classic_script,
|
||||
bool might_generate_crowdsourced_compile_hints,
|
||||
bool can_use_crowdsourced_compile_hints,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled) {
|
||||
return GetCompileOptions(
|
||||
cache_options, classic_script.CacheHandler(),
|
||||
classic_script.SourceText().length(), classic_script.SourceLocationType(),
|
||||
classic_script.SourceUrl(), might_generate_crowdsourced_compile_hints,
|
||||
can_use_crowdsourced_compile_hints,
|
||||
v8_compile_hints_magic_comment_runtime_enabled);
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode) {
|
||||
return MaybeAddCompileHintsMagic(
|
||||
GetCompileOptionsInternal(cache_options, classic_script.CacheHandler(),
|
||||
classic_script.SourceText().length(),
|
||||
classic_script.SourceLocationType(),
|
||||
classic_script.SourceUrl(),
|
||||
might_generate_crowdsourced_compile_hints,
|
||||
can_use_crowdsourced_compile_hints),
|
||||
magic_comment_mode);
|
||||
}
|
||||
|
||||
namespace {
|
||||
v8::ScriptCompiler::CompileOptions MaybeAddCompileHintsMagic(
|
||||
v8::ScriptCompiler::CompileOptions compile_options,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled) {
|
||||
if (v8_compile_hints_magic_comment_runtime_enabled) {
|
||||
return v8::ScriptCompiler::CompileOptions(
|
||||
compile_options | v8::ScriptCompiler::kFollowCompileHintsMagicComment);
|
||||
}
|
||||
return compile_options;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::tuple<v8::ScriptCompiler::CompileOptions,
|
||||
V8CodeCache::ProduceCacheOptions,
|
||||
v8::ScriptCompiler::NoCacheReason>
|
||||
@ -303,7 +339,26 @@ V8CodeCache::GetCompileOptions(
|
||||
const KURL& url,
|
||||
bool might_generate_crowdsourced_compile_hints,
|
||||
bool can_use_crowdsourced_compile_hints,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled) {
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode) {
|
||||
return MaybeAddCompileHintsMagic(
|
||||
GetCompileOptionsInternal(cache_options, cache_handler,
|
||||
source_text_length, source_location_type, url,
|
||||
might_generate_crowdsourced_compile_hints,
|
||||
can_use_crowdsourced_compile_hints),
|
||||
magic_comment_mode);
|
||||
}
|
||||
|
||||
std::tuple<v8::ScriptCompiler::CompileOptions,
|
||||
V8CodeCache::ProduceCacheOptions,
|
||||
v8::ScriptCompiler::NoCacheReason>
|
||||
V8CodeCache::GetCompileOptionsInternal(
|
||||
mojom::blink::V8CacheOptions cache_options,
|
||||
const CachedMetadataHandler* cache_handler,
|
||||
size_t source_text_length,
|
||||
ScriptSourceLocationType source_location_type,
|
||||
const KURL& url,
|
||||
bool might_generate_crowdsourced_compile_hints,
|
||||
bool can_use_crowdsourced_compile_hints) {
|
||||
static const int kMinimalCodeLength = 1024;
|
||||
v8::ScriptCompiler::NoCacheReason no_cache_reason;
|
||||
|
||||
@ -417,35 +472,24 @@ V8CodeCache::GetCompileOptions(
|
||||
ProduceCacheOptions::kSetTimeStamp,
|
||||
v8::ScriptCompiler::kNoCacheBecauseCacheTooCold);
|
||||
}
|
||||
return std::make_tuple(
|
||||
MaybeAddCompileHintsMagic(
|
||||
no_code_cache_compile_options,
|
||||
v8_compile_hints_magic_comment_runtime_enabled),
|
||||
ProduceCacheOptions::kSetTimeStamp,
|
||||
v8::ScriptCompiler::kNoCacheBecauseCacheTooCold);
|
||||
return std::make_tuple(no_code_cache_compile_options,
|
||||
ProduceCacheOptions::kSetTimeStamp,
|
||||
v8::ScriptCompiler::kNoCacheBecauseCacheTooCold);
|
||||
}
|
||||
if (local_compile_hints_enabled && HasCompileHints(cache_handler)) {
|
||||
// In this branch, the timestamp in the compile hints is hot.
|
||||
return std::make_tuple(
|
||||
MaybeAddCompileHintsMagic(
|
||||
v8::ScriptCompiler::kConsumeCompileHints,
|
||||
v8_compile_hints_magic_comment_runtime_enabled),
|
||||
v8::ScriptCompiler::kConsumeCompileHints,
|
||||
ProduceCacheOptions::kProduceCodeCache,
|
||||
v8::ScriptCompiler::kNoCacheBecauseDeferredProduceCodeCache);
|
||||
}
|
||||
return std::make_tuple(
|
||||
MaybeAddCompileHintsMagic(
|
||||
no_code_cache_compile_options,
|
||||
v8_compile_hints_magic_comment_runtime_enabled),
|
||||
ProduceCacheOptions::kProduceCodeCache,
|
||||
no_code_cache_compile_options, ProduceCacheOptions::kProduceCodeCache,
|
||||
v8::ScriptCompiler::kNoCacheBecauseDeferredProduceCodeCache);
|
||||
}
|
||||
case mojom::blink::V8CacheOptions::kCodeWithoutHeatCheck:
|
||||
return std::make_tuple(
|
||||
MaybeAddCompileHintsMagic(
|
||||
no_code_cache_compile_options,
|
||||
v8_compile_hints_magic_comment_runtime_enabled),
|
||||
ProduceCacheOptions::kProduceCodeCache,
|
||||
no_code_cache_compile_options, ProduceCacheOptions::kProduceCodeCache,
|
||||
v8::ScriptCompiler::kNoCacheBecauseDeferredProduceCodeCache);
|
||||
case mojom::blink::V8CacheOptions::kFullCodeWithoutHeatCheck:
|
||||
return std::make_tuple(
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "third_party/blink/public/mojom/v8_cache_options.mojom-blink.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_source_location_type.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_common.h"
|
||||
#include "third_party/blink/renderer/core/core_export.h"
|
||||
#include "third_party/blink/renderer/platform/bindings/v8_binding_macros.h"
|
||||
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/cached_metadata_handler.h"
|
||||
@ -83,7 +84,8 @@ class CORE_EXPORT V8CodeCache final {
|
||||
const ClassicScript&,
|
||||
bool might_generate_crowdsourced_compile_hints = false,
|
||||
bool can_use_crowdsourced_compile_hints = false,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled = false);
|
||||
v8_compile_hints::MagicCommentMode v8_compile_hints_magic_comment_mode =
|
||||
v8_compile_hints::MagicCommentMode::kNever);
|
||||
static std::tuple<v8::ScriptCompiler::CompileOptions,
|
||||
ProduceCacheOptions,
|
||||
v8::ScriptCompiler::NoCacheReason>
|
||||
@ -95,7 +97,8 @@ class CORE_EXPORT V8CodeCache final {
|
||||
const KURL& url,
|
||||
bool might_generate_crowdsourced_compile_hints = false,
|
||||
bool can_use_crowdsourced_compile_hints = false,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled = false);
|
||||
v8_compile_hints::MagicCommentMode v8_compile_hints_magic_comment_mode =
|
||||
v8_compile_hints::MagicCommentMode::kNever);
|
||||
|
||||
static bool IsFull(const CachedMetadata* metadata);
|
||||
|
||||
@ -163,6 +166,18 @@ class CORE_EXPORT V8CodeCache final {
|
||||
static void RecordCacheGetStatistics(GetMetadataType metadata_type);
|
||||
|
||||
static void RecordCacheSetStatistics(SetMetadataType metadata_type);
|
||||
|
||||
private:
|
||||
static std::tuple<v8::ScriptCompiler::CompileOptions,
|
||||
ProduceCacheOptions,
|
||||
v8::ScriptCompiler::NoCacheReason>
|
||||
GetCompileOptionsInternal(mojom::blink::V8CacheOptions cache_options,
|
||||
const CachedMetadataHandler*,
|
||||
size_t source_text_length,
|
||||
ScriptSourceLocationType,
|
||||
const KURL& url,
|
||||
bool might_generate_crowdsourced_compile_hints,
|
||||
bool can_use_crowdsourced_compile_hints);
|
||||
};
|
||||
|
||||
} // namespace blink
|
||||
|
@ -5,6 +5,8 @@
|
||||
#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_COMPILE_HINTS_COMMON_H_
|
||||
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_V8_COMPILE_HINTS_COMMON_H_
|
||||
|
||||
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
|
||||
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace blink {
|
||||
@ -13,6 +15,25 @@ class KURL;
|
||||
|
||||
namespace v8_compile_hints {
|
||||
|
||||
enum class MagicCommentMode {
|
||||
kNever = 0,
|
||||
kWhenProducingCodeCache = 1,
|
||||
kAlways = 2
|
||||
};
|
||||
|
||||
inline MagicCommentMode GetMagicCommentMode(
|
||||
ExecutionContext* execution_context) {
|
||||
if (RuntimeEnabledFeatures::JavaScriptCompileHintsMagicAlwaysRuntimeEnabled(
|
||||
execution_context)) {
|
||||
return MagicCommentMode::kAlways;
|
||||
}
|
||||
if (RuntimeEnabledFeatures::JavaScriptCompileHintsMagicRuntimeEnabled(
|
||||
execution_context)) {
|
||||
return MagicCommentMode::kWhenProducingCodeCache;
|
||||
}
|
||||
return MagicCommentMode::kNever;
|
||||
}
|
||||
|
||||
static constexpr int kBloomFilterKeySize = 16;
|
||||
static constexpr int kBloomFilterInt32Count = 2048;
|
||||
|
||||
|
@ -25,7 +25,7 @@ CompileHintsForStreaming::Builder::Builder(
|
||||
V8CrowdsourcedCompileHintsProducer* crowdsourced_compile_hints_producer,
|
||||
V8CrowdsourcedCompileHintsConsumer* crowdsourced_compile_hints_consumer,
|
||||
const KURL& resource_url,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled)
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode)
|
||||
: might_generate_crowdsourced_compile_hints_(
|
||||
crowdsourced_compile_hints_producer &&
|
||||
crowdsourced_compile_hints_producer->MightGenerateData()),
|
||||
@ -36,8 +36,7 @@ CompileHintsForStreaming::Builder::Builder(
|
||||
? crowdsourced_compile_hints_consumer->GetDataWithScriptNameHash(
|
||||
ScriptNameHash(resource_url))
|
||||
: nullptr),
|
||||
v8_compile_hints_magic_comment_runtime_enabled_(
|
||||
v8_compile_hints_magic_comment_runtime_enabled) {}
|
||||
magic_comment_mode_(magic_comment_mode) {}
|
||||
|
||||
std::unique_ptr<CompileHintsForStreaming>
|
||||
CompileHintsForStreaming::Builder::Build(
|
||||
@ -47,7 +46,10 @@ CompileHintsForStreaming::Builder::Build(
|
||||
// has_hot_timestamp.
|
||||
CHECK(!hot_cached_metadata_for_local_compile_hints || has_hot_timestamp);
|
||||
v8::ScriptCompiler::CompileOptions additional_compile_options =
|
||||
(v8_compile_hints_magic_comment_runtime_enabled_ && has_hot_timestamp)
|
||||
magic_comment_mode_ == v8_compile_hints::MagicCommentMode::kAlways ||
|
||||
(magic_comment_mode_ == v8_compile_hints::MagicCommentMode::
|
||||
kWhenProducingCodeCache &&
|
||||
has_hot_timestamp)
|
||||
? v8::ScriptCompiler::kFollowCompileHintsMagicComment
|
||||
: v8::ScriptCompiler::kNoCompileOptions;
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "base/types/pass_key.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_code_cache.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_consumer.h"
|
||||
#include "third_party/blink/renderer/core/core_export.h"
|
||||
#include "v8/include/v8.h"
|
||||
@ -37,7 +38,7 @@ class CORE_EXPORT CompileHintsForStreaming {
|
||||
V8CrowdsourcedCompileHintsProducer* crowdsourced_compile_hints_producer,
|
||||
V8CrowdsourcedCompileHintsConsumer* crowdsourced_compile_hints_consumer,
|
||||
const KURL& resource_url,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled);
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode);
|
||||
Builder(const Builder&) = delete;
|
||||
Builder& operator=(const Builder&) = delete;
|
||||
~Builder() = default;
|
||||
@ -52,7 +53,7 @@ class CORE_EXPORT CompileHintsForStreaming {
|
||||
const bool might_generate_crowdsourced_compile_hints_;
|
||||
std::unique_ptr<V8CrowdsourcedCompileHintsConsumer::DataAndScriptNameHash>
|
||||
crowdsourced_compile_hint_callback_data_;
|
||||
const bool v8_compile_hints_magic_comment_runtime_enabled_;
|
||||
const v8_compile_hints::MagicCommentMode magic_comment_mode_;
|
||||
};
|
||||
|
||||
// For producing compile hints or just transmitting the compiler options.
|
||||
|
@ -44,8 +44,7 @@ TEST_F(CompileHintsForStreamingTest, NoCrowdsourcedNoLocalNoMagicComment1) {
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/false);
|
||||
KURL("https://example.com/"), v8_compile_hints::MagicCommentMode::kNever);
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming = std::move(builder).Build(
|
||||
/*cached_metadata=*/nullptr, /*has_hot_timestamp=*/true);
|
||||
@ -63,7 +62,7 @@ TEST_F(CompileHintsForStreamingTest, NoCrowdsourcedNoLocalNoMagicComment2) {
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache);
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming = std::move(builder).Build(
|
||||
/*cached_metadata=*/nullptr, /*has_hot_timestamp=*/false);
|
||||
@ -74,6 +73,25 @@ TEST_F(CompileHintsForStreamingTest, NoCrowdsourcedNoLocalNoMagicComment2) {
|
||||
compile_hints_for_streaming->compile_options());
|
||||
}
|
||||
|
||||
TEST_F(CompileHintsForStreamingTest,
|
||||
NoCrowdsourcedNoLocalButMagicCommentAlways) {
|
||||
base::test::ScopedFeatureList scoped_feature_list;
|
||||
scoped_feature_list.InitAndDisableFeature(features::kLocalCompileHints);
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
v8_compile_hints::MagicCommentMode::kAlways);
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming = std::move(builder).Build(
|
||||
/*cached_metadata=*/nullptr, /*has_hot_timestamp=*/false);
|
||||
histogram_tester.ExpectUniqueSample(kStatusHistogram,
|
||||
Status::kNoCompileHintsStreaming, 1);
|
||||
ASSERT_TRUE(compile_hints_for_streaming);
|
||||
EXPECT_EQ(v8::ScriptCompiler::kFollowCompileHintsMagicComment,
|
||||
compile_hints_for_streaming->compile_options());
|
||||
}
|
||||
|
||||
TEST_F(CompileHintsForStreamingTest, NoCrowdsourcedNoLocalButMagicComment) {
|
||||
base::test::ScopedFeatureList scoped_feature_list;
|
||||
scoped_feature_list.InitAndDisableFeature(features::kLocalCompileHints);
|
||||
@ -81,7 +99,7 @@ TEST_F(CompileHintsForStreamingTest, NoCrowdsourcedNoLocalButMagicComment) {
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache);
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming = std::move(builder).Build(
|
||||
/*cached_metadata=*/nullptr, /*has_hot_timestamp=*/true);
|
||||
@ -98,8 +116,7 @@ TEST_F(CompileHintsForStreamingTest, ProduceLocalNoMagicComment) {
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
KURL("https://example.com/"), v8_compile_hints::MagicCommentMode::kNever);
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming = std::move(builder).Build(
|
||||
/*cached_metadata=*/nullptr, /*has_hot_timestamp=*/false);
|
||||
@ -118,8 +135,7 @@ TEST_F(CompileHintsForStreamingTest, ConsumeLocalNoMagicComment) {
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/false);
|
||||
KURL("https://example.com/"), v8_compile_hints::MagicCommentMode::kNever);
|
||||
const uint32_t kCacheTagCompileHints = 2;
|
||||
const uint64_t kDummyTag = 1;
|
||||
Vector<uint8_t> dummy_data(100);
|
||||
@ -139,6 +155,35 @@ TEST_F(CompileHintsForStreamingTest, ConsumeLocalNoMagicComment) {
|
||||
EXPECT_TRUE(compile_hints_for_streaming->GetCompileHintCallbackData());
|
||||
}
|
||||
|
||||
TEST_F(CompileHintsForStreamingTest, ConsumeLocalMagicCommentAlways) {
|
||||
base::test::ScopedFeatureList scoped_feature_list;
|
||||
scoped_feature_list.InitAndEnableFeature(features::kLocalCompileHints);
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
v8_compile_hints::MagicCommentMode::kAlways);
|
||||
const uint32_t kCacheTagCompileHints = 2;
|
||||
const uint64_t kDummyTag = 1;
|
||||
Vector<uint8_t> dummy_data(100);
|
||||
scoped_refptr<CachedMetadata> metadata = CachedMetadata::Create(
|
||||
kCacheTagCompileHints, dummy_data.data(), dummy_data.size(), kDummyTag);
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming =
|
||||
std::move(builder).Build(std::move(metadata), /*has_hot_timestamp=*/true);
|
||||
histogram_tester.ExpectUniqueSample(
|
||||
kStatusHistogram, Status::kConsumeLocalCompileHintsStreaming, 1);
|
||||
ASSERT_TRUE(compile_hints_for_streaming);
|
||||
EXPECT_EQ(compile_hints_for_streaming->compile_options(),
|
||||
v8::ScriptCompiler::CompileOptions(
|
||||
v8::ScriptCompiler::kConsumeCompileHints |
|
||||
v8::ScriptCompiler::kFollowCompileHintsMagicComment));
|
||||
EXPECT_EQ(
|
||||
compile_hints_for_streaming->GetCompileHintCallback(),
|
||||
v8::CompileHintCallback(V8LocalCompileHintsConsumer::GetCompileHint));
|
||||
EXPECT_TRUE(compile_hints_for_streaming->GetCompileHintCallbackData());
|
||||
}
|
||||
|
||||
TEST_F(CompileHintsForStreamingTest, ConsumeLocalMagicComment) {
|
||||
base::test::ScopedFeatureList scoped_feature_list;
|
||||
scoped_feature_list.InitAndEnableFeature(features::kLocalCompileHints);
|
||||
@ -146,7 +191,8 @@ TEST_F(CompileHintsForStreamingTest, ConsumeLocalMagicComment) {
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache);
|
||||
|
||||
const uint32_t kCacheTagCompileHints = 2;
|
||||
const uint64_t kDummyTag = 1;
|
||||
Vector<uint8_t> dummy_data(100);
|
||||
@ -175,8 +221,7 @@ TEST_F(CompileHintsForStreamingTest,
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/false);
|
||||
KURL("https://example.com/"), v8_compile_hints::MagicCommentMode::kNever);
|
||||
const uint32_t kCacheTagCompileHints = 2;
|
||||
const uint64_t kDummyTag = 1;
|
||||
Vector<uint8_t> dummy_data(1); // Too small.
|
||||
@ -189,6 +234,28 @@ TEST_F(CompileHintsForStreamingTest,
|
||||
compile_hints_for_streaming->compile_options());
|
||||
}
|
||||
|
||||
TEST_F(CompileHintsForStreamingTest,
|
||||
FailedToConsumeLocalWrongSizeMagicCommentAlways) {
|
||||
base::test::ScopedFeatureList scoped_feature_list;
|
||||
scoped_feature_list.InitAndEnableFeature(features::kLocalCompileHints);
|
||||
base::HistogramTester histogram_tester;
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
v8_compile_hints::MagicCommentMode::kAlways);
|
||||
const uint32_t kCacheTagCompileHints = 2;
|
||||
const uint64_t kDummyTag = 1;
|
||||
Vector<uint8_t> dummy_data(1); // Too small.
|
||||
scoped_refptr<CachedMetadata> metadata = CachedMetadata::Create(
|
||||
kCacheTagCompileHints, dummy_data.data(), dummy_data.size(), kDummyTag);
|
||||
auto compile_hints_for_streaming =
|
||||
std::move(builder).Build(std::move(metadata), /*has_hot_timestamp=*/true);
|
||||
EXPECT_TRUE(compile_hints_for_streaming);
|
||||
EXPECT_EQ(v8::ScriptCompiler::kFollowCompileHintsMagicComment,
|
||||
compile_hints_for_streaming->compile_options());
|
||||
}
|
||||
|
||||
TEST_F(CompileHintsForStreamingTest,
|
||||
FailedToConsumeLocalWrongSizeMagicComment) {
|
||||
base::test::ScopedFeatureList scoped_feature_list;
|
||||
@ -198,7 +265,7 @@ TEST_F(CompileHintsForStreamingTest,
|
||||
/*crowdsourced_compile_hints_producer=*/nullptr,
|
||||
/*crowdsourced_compile_hints_consumer=*/nullptr,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache);
|
||||
const uint32_t kCacheTagCompileHints = 2;
|
||||
const uint64_t kDummyTag = 1;
|
||||
Vector<uint8_t> dummy_data(1); // Too small.
|
||||
@ -228,7 +295,7 @@ TEST_F(CompileHintsForStreamingTest, ConsumeCrowdsourcedHintNoMagicComment) {
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
crowdsourced_compile_hints_producer, crowdsourced_compile_hints_consumer,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache);
|
||||
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming = std::move(builder).Build(
|
||||
@ -268,7 +335,7 @@ TEST_F(CompileHintsForStreamingTest, PreferCrowdsourcedHints) {
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
crowdsourced_compile_hints_producer, crowdsourced_compile_hints_consumer,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache);
|
||||
|
||||
auto compile_hints_for_streaming =
|
||||
std::move(builder).Build(metadata, /*has_hot_timestamp=*/true);
|
||||
@ -306,7 +373,7 @@ TEST_F(CompileHintsForStreamingTest, ProduceCrowdsourcedHintNoMagicComment) {
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
crowdsourced_compile_hints_producer, crowdsourced_compile_hints_consumer,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache);
|
||||
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming = std::move(builder).Build(
|
||||
@ -348,7 +415,7 @@ TEST_F(CompileHintsForStreamingTest, ProduceCrowdsourcedHintMagicComment) {
|
||||
auto builder = CompileHintsForStreaming::Builder(
|
||||
crowdsourced_compile_hints_producer, crowdsourced_compile_hints_consumer,
|
||||
KURL("https://example.com/"),
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/true);
|
||||
v8_compile_hints::MagicCommentMode::kWhenProducingCodeCache);
|
||||
|
||||
base::HistogramTester histogram_tester;
|
||||
auto compile_hints_for_streaming = std::move(builder).Build(
|
||||
|
@ -409,12 +409,19 @@ v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule(
|
||||
isolate->GetCurrentContext(), streamer->Source(v8::ScriptType::kModule),
|
||||
code, origin);
|
||||
} else {
|
||||
switch (compile_options) {
|
||||
switch (static_cast<int>(compile_options)) {
|
||||
// TODO(40286622): Compile hints for modules.
|
||||
case v8::ScriptCompiler::kProduceCompileHints:
|
||||
case v8::ScriptCompiler::kConsumeCompileHints:
|
||||
compile_options = v8::ScriptCompiler::kNoCompileOptions;
|
||||
case v8::ScriptCompiler::kFollowCompileHintsMagicComment |
|
||||
v8::ScriptCompiler::kProduceCompileHints:
|
||||
case v8::ScriptCompiler::kFollowCompileHintsMagicComment |
|
||||
v8::ScriptCompiler::kConsumeCompileHints:
|
||||
compile_options = v8::ScriptCompiler::CompileOptions(
|
||||
compile_options & (~(v8::ScriptCompiler::kProduceCompileHints |
|
||||
v8::ScriptCompiler::kConsumeCompileHints)));
|
||||
ABSL_FALLTHROUGH_INTENDED;
|
||||
case v8::ScriptCompiler::kFollowCompileHintsMagicComment:
|
||||
case v8::ScriptCompiler::kNoCompileOptions:
|
||||
case v8::ScriptCompiler::kEagerCompile: {
|
||||
base::UmaHistogramEnumeration(
|
||||
@ -628,16 +635,13 @@ ScriptEvaluationResult V8ScriptRunner::CompileAndRunScript(
|
||||
const bool can_use_crowdsourced_compile_hints =
|
||||
is_http && page != nullptr && page->MainFrame() == frame &&
|
||||
page->GetV8CrowdsourcedCompileHintsConsumer().HasData();
|
||||
const bool v8_compile_hints_magic_comment_runtime_enabled =
|
||||
RuntimeEnabledFeatures::JavaScriptCompileHintsMagicRuntimeEnabled(
|
||||
execution_context);
|
||||
|
||||
std::tie(compile_options, produce_cache_options, no_cache_reason) =
|
||||
V8CodeCache::GetCompileOptions(
|
||||
execution_context->GetV8CacheOptions(), *classic_script,
|
||||
might_generate_crowdsourced_compile_hints,
|
||||
can_use_crowdsourced_compile_hints,
|
||||
v8_compile_hints_magic_comment_runtime_enabled);
|
||||
v8_compile_hints::GetMagicCommentMode(execution_context));
|
||||
|
||||
v8::ScriptOrigin origin = classic_script->CreateScriptOrigin(isolate);
|
||||
v8::MaybeLocal<v8::Value> maybe_result;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "third_party/blink/public/mojom/script/script_type.mojom-blink-forward.h"
|
||||
#include "third_party/blink/public/mojom/script/script_type.mojom-shared.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_streamer.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_common.h"
|
||||
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
|
||||
#include "third_party/blink/renderer/core/inspector/console_message.h"
|
||||
#include "third_party/blink/renderer/core/loader/resource/script_resource.h"
|
||||
@ -46,14 +47,11 @@ void DocumentModuleScriptFetcher::Fetch(
|
||||
kNoCompileHintsProducer = nullptr;
|
||||
constexpr v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
kNoCompileHintsConsumer = nullptr;
|
||||
const bool v8_compile_hints_magic_comment_runtime_enabled =
|
||||
RuntimeEnabledFeatures::JavaScriptCompileHintsMagicRuntimeEnabled(
|
||||
GetExecutionContext());
|
||||
ScriptResource::Fetch(fetch_params, fetch_client_settings_object_fetcher,
|
||||
this, GetExecutionContext()->GetIsolate(),
|
||||
streaming_allowed, kNoCompileHintsProducer,
|
||||
kNoCompileHintsConsumer,
|
||||
v8_compile_hints_magic_comment_runtime_enabled);
|
||||
ScriptResource::Fetch(
|
||||
fetch_params, fetch_client_settings_object_fetcher, this,
|
||||
GetExecutionContext()->GetIsolate(), streaming_allowed,
|
||||
kNoCompileHintsProducer, kNoCompileHintsConsumer,
|
||||
v8_compile_hints::GetMagicCommentMode(GetExecutionContext()));
|
||||
}
|
||||
|
||||
void DocumentModuleScriptFetcher::NotifyFinished(Resource* resource) {
|
||||
|
@ -85,12 +85,11 @@ void WorkerModuleScriptFetcher::Fetch(
|
||||
kNoCompileHintsProducer = nullptr;
|
||||
constexpr v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
kNoCompileHintsConsumer = nullptr;
|
||||
constexpr bool kNoV8CompileHintsMagicCommentRuntimeEnabledFeature = false;
|
||||
ScriptResource::Fetch(fetch_params, fetch_client_settings_object_fetcher,
|
||||
this, global_scope_->GetIsolate(),
|
||||
ScriptResource::kNoStreaming, kNoCompileHintsProducer,
|
||||
kNoCompileHintsConsumer,
|
||||
kNoV8CompileHintsMagicCommentRuntimeEnabledFeature);
|
||||
v8_compile_hints::MagicCommentMode::kNever);
|
||||
}
|
||||
|
||||
void WorkerModuleScriptFetcher::Trace(Visitor* visitor) const {
|
||||
|
@ -47,12 +47,11 @@ void WorkletModuleScriptFetcher::Fetch(
|
||||
kNoCompileHintsProducer = nullptr;
|
||||
constexpr v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
kNoCompileHintsConsumer = nullptr;
|
||||
constexpr bool kNoV8CompileHintsMagicCommentRuntimeEnabledFeature = false;
|
||||
ScriptResource::Fetch(fetch_params, fetch_client_settings_object_fetcher,
|
||||
this, global_scope_->GetIsolate(),
|
||||
ScriptResource::kNoStreaming, kNoCompileHintsProducer,
|
||||
kNoCompileHintsConsumer,
|
||||
kNoV8CompileHintsMagicCommentRuntimeEnabledFeature);
|
||||
v8_compile_hints::MagicCommentMode::kNever);
|
||||
}
|
||||
|
||||
void WorkletModuleScriptFetcher::NotifyFinished(Resource* resource) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "third_party/blink/public/platform/platform.h"
|
||||
#include "third_party/blink/public/platform/web_prescient_networking.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_common.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_idle_request_options.h"
|
||||
#include "third_party/blink/renderer/core/css/media_list.h"
|
||||
#include "third_party/blink/renderer/core/css/media_query_evaluator.h"
|
||||
@ -959,15 +960,13 @@ Resource* PreloadHelper::StartPreload(ResourceType type,
|
||||
|
||||
params.SetRequestContext(mojom::blink::RequestContextType::SCRIPT);
|
||||
params.SetRequestDestination(network::mojom::RequestDestination::kScript);
|
||||
const bool v8_compile_hints_magic_comment_runtime_enabled =
|
||||
RuntimeEnabledFeatures::JavaScriptCompileHintsMagicRuntimeEnabled(
|
||||
document.GetExecutionContext());
|
||||
|
||||
resource = ScriptResource::Fetch(
|
||||
params, resource_fetcher, nullptr, document.GetAgent().isolate(),
|
||||
ScriptResource::kAllowStreaming, v8_compile_hints_producer,
|
||||
v8_compile_hints_consumer,
|
||||
v8_compile_hints_magic_comment_runtime_enabled);
|
||||
v8_compile_hints::GetMagicCommentMode(
|
||||
document.GetExecutionContext()));
|
||||
break;
|
||||
}
|
||||
case ResourceType::kCSSStyleSheet:
|
||||
|
@ -90,11 +90,10 @@ class ResourceLoaderCodeCacheTest : public testing::Test {
|
||||
kNoCompileHintsProducer = nullptr;
|
||||
constexpr v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
kNoCompileHintsConsumer = nullptr;
|
||||
constexpr bool kNoV8CompileHintsMagicCommentRuntimeEnabledFeature = false;
|
||||
resource_ = ScriptResource::Fetch(
|
||||
params, fetcher, nullptr, isolate, ScriptResource::kNoStreaming,
|
||||
kNoCompileHintsProducer, kNoCompileHintsConsumer,
|
||||
kNoV8CompileHintsMagicCommentRuntimeEnabledFeature);
|
||||
v8_compile_hints::MagicCommentMode::kNever);
|
||||
loader_ = resource_->Loader();
|
||||
|
||||
response_ = ResourceResponse(url);
|
||||
|
@ -106,15 +106,14 @@ ScriptResource* ScriptResource::Fetch(
|
||||
v8_compile_hints_producer,
|
||||
v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
v8_compile_hints_consumer,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled) {
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode) {
|
||||
DCHECK(IsRequestContextSupported(
|
||||
params.GetResourceRequest().GetRequestContext()));
|
||||
auto* resource = To<ScriptResource>(fetcher->RequestResource(
|
||||
params,
|
||||
ScriptResourceFactory(isolate, streaming_allowed,
|
||||
v8_compile_hints_producer,
|
||||
v8_compile_hints_consumer,
|
||||
v8_compile_hints_magic_comment_runtime_enabled,
|
||||
v8_compile_hints_consumer, magic_comment_mode,
|
||||
params.GetScriptType()),
|
||||
client));
|
||||
return resource;
|
||||
@ -134,7 +133,7 @@ ScriptResource* ScriptResource::CreateForTest(
|
||||
request, options, decoder_options, isolate, kNoStreaming,
|
||||
/*v8_compile_hints_producer=*/nullptr,
|
||||
/*v8_compile_hints_consumer=*/nullptr,
|
||||
/*v8_compile_hints_magic_comment_runtime_enabled=*/false, script_type);
|
||||
v8_compile_hints::MagicCommentMode::kNever, script_type);
|
||||
}
|
||||
|
||||
ScriptResource::ScriptResource(
|
||||
@ -147,7 +146,7 @@ ScriptResource::ScriptResource(
|
||||
v8_compile_hints_producer,
|
||||
v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
v8_compile_hints_consumer,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled,
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode,
|
||||
mojom::blink::ScriptType initial_request_script_type)
|
||||
: TextResource(resource_request,
|
||||
ResourceType::kScript,
|
||||
@ -162,8 +161,7 @@ ScriptResource::ScriptResource(
|
||||
std::make_unique<TextResourceDecoder>(decoder_options)),
|
||||
v8_compile_hints_producer_(v8_compile_hints_producer),
|
||||
v8_compile_hints_consumer_(v8_compile_hints_consumer),
|
||||
v8_compile_hints_magic_comment_runtime_enabled_(
|
||||
v8_compile_hints_magic_comment_runtime_enabled) {
|
||||
magic_comment_mode_(magic_comment_mode) {
|
||||
static bool script_streaming_enabled =
|
||||
base::FeatureList::IsEnabled(features::kScriptStreaming);
|
||||
static bool script_streaming_for_non_http_enabled =
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "third_party/blink/public/mojom/script/script_type.mojom-shared.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_cache_consumer.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_streamer.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_common.h"
|
||||
#include "third_party/blink/renderer/core/core_export.h"
|
||||
#include "third_party/blink/renderer/core/loader/resource/text_resource.h"
|
||||
#include "third_party/blink/renderer/platform/bindings/parkable_string.h"
|
||||
@ -78,7 +79,7 @@ class CORE_EXPORT ScriptResource final : public TextResource {
|
||||
StreamingAllowed,
|
||||
v8_compile_hints::V8CrowdsourcedCompileHintsProducer*,
|
||||
v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled);
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode);
|
||||
|
||||
// Public for testing
|
||||
static ScriptResource* CreateForTest(
|
||||
@ -94,7 +95,7 @@ class CORE_EXPORT ScriptResource final : public TextResource {
|
||||
StreamingAllowed,
|
||||
v8_compile_hints::V8CrowdsourcedCompileHintsProducer*,
|
||||
v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled,
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode,
|
||||
mojom::blink::ScriptType);
|
||||
~ScriptResource() override;
|
||||
|
||||
@ -164,8 +165,8 @@ class CORE_EXPORT ScriptResource final : public TextResource {
|
||||
return v8_compile_hints_consumer_.Get();
|
||||
}
|
||||
|
||||
bool GetV8CompileHintsMagicCommentRuntimeFeatureEnabled() const {
|
||||
return v8_compile_hints_magic_comment_runtime_enabled_;
|
||||
v8_compile_hints::MagicCommentMode GetV8CompileHintsMagicCommentMode() const {
|
||||
return magic_comment_mode_;
|
||||
}
|
||||
|
||||
// Returns the Isolate if set. This may be null.
|
||||
@ -233,7 +234,7 @@ class CORE_EXPORT ScriptResource final : public TextResource {
|
||||
v8_compile_hints_producer,
|
||||
v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
v8_compile_hints_consumer,
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled,
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode,
|
||||
mojom::blink::ScriptType initial_request_script_type)
|
||||
: ResourceFactory(ResourceType::kScript,
|
||||
TextResourceDecoderOptions::kPlainTextContent),
|
||||
@ -241,8 +242,7 @@ class CORE_EXPORT ScriptResource final : public TextResource {
|
||||
streaming_allowed_(streaming_allowed),
|
||||
v8_compile_hints_producer_(v8_compile_hints_producer),
|
||||
v8_compile_hints_consumer_(v8_compile_hints_consumer),
|
||||
v8_compile_hints_magic_comment_runtime_enabled_(
|
||||
v8_compile_hints_magic_comment_runtime_enabled),
|
||||
magic_comment_mode_(magic_comment_mode),
|
||||
initial_request_script_type_(initial_request_script_type) {}
|
||||
|
||||
Resource* Create(
|
||||
@ -252,8 +252,7 @@ class CORE_EXPORT ScriptResource final : public TextResource {
|
||||
return MakeGarbageCollected<ScriptResource>(
|
||||
request, options, decoder_options, isolate_, streaming_allowed_,
|
||||
v8_compile_hints_producer_, v8_compile_hints_consumer_,
|
||||
v8_compile_hints_magic_comment_runtime_enabled_,
|
||||
initial_request_script_type_);
|
||||
magic_comment_mode_, initial_request_script_type_);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -268,7 +267,7 @@ class CORE_EXPORT ScriptResource final : public TextResource {
|
||||
// ExecutionContext.
|
||||
// TODO(42203853): Remove this once explicit compile hints have launched and
|
||||
// the feature is always on.
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled_;
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode_;
|
||||
mojom::blink::ScriptType initial_request_script_type_;
|
||||
};
|
||||
|
||||
@ -328,7 +327,7 @@ class CORE_EXPORT ScriptResource final : public TextResource {
|
||||
// ExecutionContext.
|
||||
// TODO(42203853): Remove this once explicit compile hints have launched and
|
||||
// the feature is always on.
|
||||
bool v8_compile_hints_magic_comment_runtime_enabled_;
|
||||
v8_compile_hints::MagicCommentMode magic_comment_mode_;
|
||||
|
||||
Member<BackgroundResourceScriptStreamer> background_streamer_;
|
||||
};
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/script_streamer.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
|
||||
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_common.h"
|
||||
#include "third_party/blink/renderer/core/dom/document.h"
|
||||
#include "third_party/blink/renderer/core/dom/scriptable_document_parser.h"
|
||||
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
|
||||
@ -103,14 +104,12 @@ ClassicPendingScript* ClassicPendingScript::Fetch(
|
||||
compile_hints_producer = &page->GetV8CrowdsourcedCompileHintsProducer();
|
||||
compile_hints_consumer = &page->GetV8CrowdsourcedCompileHintsConsumer();
|
||||
}
|
||||
const bool v8_compile_hints_magic_comment_runtime_enabled =
|
||||
RuntimeEnabledFeatures::JavaScriptCompileHintsMagicRuntimeEnabled(
|
||||
element_document.GetExecutionContext());
|
||||
|
||||
ScriptResource::Fetch(params, element_document.Fetcher(), pending_script,
|
||||
context->GetIsolate(), ScriptResource::kAllowStreaming,
|
||||
compile_hints_producer, compile_hints_consumer,
|
||||
v8_compile_hints_magic_comment_runtime_enabled);
|
||||
v8_compile_hints::GetMagicCommentMode(
|
||||
element_document.GetExecutionContext()));
|
||||
pending_script->CheckState();
|
||||
return pending_script;
|
||||
}
|
||||
|
@ -214,11 +214,10 @@ void PossiblyFetchBlockedDocWriteScript(
|
||||
kNoCompileHintsProducer = nullptr;
|
||||
constexpr v8_compile_hints::V8CrowdsourcedCompileHintsConsumer*
|
||||
kNoCompileHintsConsumer = nullptr;
|
||||
constexpr bool kNoV8CompileHintsMagicCommentRuntimeEnabledFeature = false;
|
||||
ScriptResource::Fetch(params, element_document.Fetcher(), nullptr,
|
||||
context->GetIsolate(), ScriptResource::kNoStreaming,
|
||||
kNoCompileHintsProducer, kNoCompileHintsConsumer,
|
||||
kNoV8CompileHintsMagicCommentRuntimeEnabledFeature);
|
||||
v8_compile_hints::MagicCommentMode::kNever);
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
@ -2464,6 +2464,11 @@
|
||||
name: "InvisibleSVGAnimationThrottling",
|
||||
status: "stable",
|
||||
},
|
||||
{
|
||||
name: "JavaScriptCompileHintsMagicAlwaysRuntime",
|
||||
status: "experimental",
|
||||
origin_trial_feature_name: "JavaScriptCompileHintsMagicAlways",
|
||||
},
|
||||
{
|
||||
name: "JavaScriptCompileHintsMagicRuntime",
|
||||
status: "experimental",
|
||||
|
Reference in New Issue
Block a user