From 374fd77e460527258abc42e5ba5657b015682f9a Mon Sep 17 00:00:00 2001 From: ShouruiSong Date: Mon, 10 Mar 2025 15:18:49 +0800 Subject: [PATCH] [Optimize] Support deriving a new ElementBinaryReader from ElementBinaryReader. Described as title. With this feature, we can construct a new ElementBinaryReader and use it in an asynchronous thread to perform some necessary parsing operations. This enables multi-threaded parallel parsing of Element Templates, thereby optimizing performance. issue:m-6083199326 AutoSubmit:True --- core/runtime/vm/lepus/base_binary_reader.h | 1 - .../binary_decoder/element_binary_reader.cc | 14 +++++++++++++- .../binary_decoder/element_binary_reader.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/runtime/vm/lepus/base_binary_reader.h b/core/runtime/vm/lepus/base_binary_reader.h index 0f18a177..f8a9a672 100644 --- a/core/runtime/vm/lepus/base_binary_reader.h +++ b/core/runtime/vm/lepus/base_binary_reader.h @@ -160,7 +160,6 @@ class BaseBinaryReader : public BinaryReader { #endif tasm::CompileOptions compile_options_; - private: std::vector string_list_; }; diff --git a/core/template_bundle/template_codec/binary_decoder/element_binary_reader.cc b/core/template_bundle/template_codec/binary_decoder/element_binary_reader.cc index a9582f71..b51b3ea3 100644 --- a/core/template_bundle/template_codec/binary_decoder/element_binary_reader.cc +++ b/core/template_bundle/template_codec/binary_decoder/element_binary_reader.cc @@ -396,8 +396,20 @@ bool ElementBinaryReader::ConstructElement(ElementSectionEnum section_type, return true; } -// These are the APIs used for decoding data and return element infos: +std::unique_ptr +ElementBinaryReader::DeriveElementBinaryReader() { + auto reader = + std::make_unique(stream_->DeriveInputStream()); + reader->element_templates_router_ = element_templates_router_; + reader->string_key_parsed_styles_router_ = string_key_parsed_styles_router_; + + reader->compile_options_ = compile_options_; + reader->string_list_ = string_list(); + return reader; +} + +// These are the APIs used for decoding data and return element infos: // Lazy decode. Only decode templates router. The // decoding of the template waits until it is actually needed. bool ElementBinaryReader::DecodeElementTemplatesRouter() { diff --git a/core/template_bundle/template_codec/binary_decoder/element_binary_reader.h b/core/template_bundle/template_codec/binary_decoder/element_binary_reader.h index 82b0e8a8..b38071bb 100644 --- a/core/template_bundle/template_codec/binary_decoder/element_binary_reader.h +++ b/core/template_bundle/template_codec/binary_decoder/element_binary_reader.h @@ -47,6 +47,8 @@ class ElementBinaryReader : public LynxBinaryBaseCSSReader { std::shared_ptr DecodeTemplatesInfoWithKey( const std::string& key); + std::unique_ptr DeriveElementBinaryReader(); + protected: // These are the APIs used for decoding data into fiber elements. virtual bool DecodeElementChildrenSection(fml::RefPtr& element,