Commit 8d6e5bc9 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[serializer][web snapshot] Speed up ValueDeserializer

- Unroll loop in ReadVarInt to skip checks for uncommon branches and
  improve by ~15%
- Use cage_base more aggressively
- Use more dehandlified code if possible
- Allow allocating strings directly in old-space to avoid filling up the
  new space when deserialising web-snapshots

Cleanup:
- ThrowDataCloneError now returns Nothing<bool>() for more consistency

Bug: v8:11525
Change-Id: I69ac635e2bcab83e92fba5ab34603146fa21f043
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3437049Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78999}
parent 0823b36d
This diff is collapsed.
...@@ -153,9 +153,11 @@ class ValueSerializer { ...@@ -153,9 +153,11 @@ class ValueSerializer {
* Asks the delegate to handle an error that occurred during data cloning, by * Asks the delegate to handle an error that occurred during data cloning, by
* throwing an exception appropriate for the host. * throwing an exception appropriate for the host.
*/ */
void ThrowDataCloneError(MessageTemplate template_index); V8_NOINLINE Maybe<bool> ThrowDataCloneError(MessageTemplate template_index)
V8_NOINLINE void ThrowDataCloneError(MessageTemplate template_index, V8_WARN_UNUSED_RESULT;
Handle<Object> arg0); V8_NOINLINE Maybe<bool> ThrowDataCloneError(MessageTemplate template_index,
Handle<Object> arg0)
V8_WARN_UNUSED_RESULT;
Maybe<bool> ThrowIfOutOfMemory(); Maybe<bool> ThrowIfOutOfMemory();
...@@ -243,11 +245,13 @@ class ValueDeserializer { ...@@ -243,11 +245,13 @@ class ValueDeserializer {
void ConsumeTag(SerializationTag peeked_tag); void ConsumeTag(SerializationTag peeked_tag);
Maybe<SerializationTag> ReadTag() V8_WARN_UNUSED_RESULT; Maybe<SerializationTag> ReadTag() V8_WARN_UNUSED_RESULT;
template <typename T> template <typename T>
Maybe<T> ReadVarint() V8_WARN_UNUSED_RESULT; V8_INLINE Maybe<T> ReadVarint() V8_WARN_UNUSED_RESULT;
template <typename T>
V8_NOINLINE Maybe<T> ReadVarintLoop() V8_WARN_UNUSED_RESULT;
template <typename T> template <typename T>
Maybe<T> ReadZigZag() V8_WARN_UNUSED_RESULT; Maybe<T> ReadZigZag() V8_WARN_UNUSED_RESULT;
Maybe<double> ReadDouble() V8_WARN_UNUSED_RESULT; Maybe<double> ReadDouble() V8_WARN_UNUSED_RESULT;
Maybe<base::Vector<const uint8_t>> ReadRawBytes(int size) Maybe<base::Vector<const uint8_t>> ReadRawBytes(size_t size)
V8_WARN_UNUSED_RESULT; V8_WARN_UNUSED_RESULT;
// Reads a string if it matches the one provided. // Reads a string if it matches the one provided.
...@@ -266,9 +270,12 @@ class ValueDeserializer { ...@@ -266,9 +270,12 @@ class ValueDeserializer {
// Reading V8 objects of specific kinds. // Reading V8 objects of specific kinds.
// The tag is assumed to have already been read. // The tag is assumed to have already been read.
MaybeHandle<BigInt> ReadBigInt() V8_WARN_UNUSED_RESULT; MaybeHandle<BigInt> ReadBigInt() V8_WARN_UNUSED_RESULT;
MaybeHandle<String> ReadUtf8String() V8_WARN_UNUSED_RESULT; MaybeHandle<String> ReadUtf8String(
MaybeHandle<String> ReadOneByteString() V8_WARN_UNUSED_RESULT; AllocationType allocation = AllocationType::kYoung) V8_WARN_UNUSED_RESULT;
MaybeHandle<String> ReadTwoByteString() V8_WARN_UNUSED_RESULT; MaybeHandle<String> ReadOneByteString(
AllocationType allocation = AllocationType::kYoung) V8_WARN_UNUSED_RESULT;
MaybeHandle<String> ReadTwoByteString(
AllocationType allocation = AllocationType::kYoung) V8_WARN_UNUSED_RESULT;
MaybeHandle<JSObject> ReadJSObject() V8_WARN_UNUSED_RESULT; MaybeHandle<JSObject> ReadJSObject() V8_WARN_UNUSED_RESULT;
MaybeHandle<JSArray> ReadSparseJSArray() V8_WARN_UNUSED_RESULT; MaybeHandle<JSArray> ReadSparseJSArray() V8_WARN_UNUSED_RESULT;
MaybeHandle<JSArray> ReadDenseJSArray() V8_WARN_UNUSED_RESULT; MaybeHandle<JSArray> ReadDenseJSArray() V8_WARN_UNUSED_RESULT;
......
...@@ -1239,7 +1239,8 @@ void WebSnapshotDeserializer::DeserializeStrings() { ...@@ -1239,7 +1239,8 @@ void WebSnapshotDeserializer::DeserializeStrings() {
strings_handle_ = isolate_->factory()->NewFixedArray(string_count_); strings_handle_ = isolate_->factory()->NewFixedArray(string_count_);
strings_ = *strings_handle_; strings_ = *strings_handle_;
for (uint32_t i = 0; i < string_count_; ++i) { for (uint32_t i = 0; i < string_count_; ++i) {
MaybeHandle<String> maybe_string = deserializer_.ReadUtf8String(); MaybeHandle<String> maybe_string =
deserializer_.ReadUtf8String(AllocationType::kOld);
Handle<String> string; Handle<String> string;
if (!maybe_string.ToHandle(&string)) { if (!maybe_string.ToHandle(&string)) {
Throw("Malformed string"); Throw("Malformed string");
...@@ -1257,7 +1258,7 @@ String WebSnapshotDeserializer::ReadString(bool internalize) { ...@@ -1257,7 +1258,7 @@ String WebSnapshotDeserializer::ReadString(bool internalize) {
return ReadOnlyRoots(isolate_).empty_string(); return ReadOnlyRoots(isolate_).empty_string();
} }
String string = String::cast(strings_.get(string_id)); String string = String::cast(strings_.get(string_id));
if (internalize && !string.IsInternalizedString()) { if (internalize && !string.IsInternalizedString(isolate_)) {
string = *isolate_->factory()->InternalizeString(handle(string, isolate_)); string = *isolate_->factory()->InternalizeString(handle(string, isolate_));
strings_.set(string_id, string); strings_.set(string_id, string);
} }
......
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