Skip to content

Commit

Permalink
[Optimize] Support deriving a new ElementBinaryReader from ElementBin…
Browse files Browse the repository at this point in the history
…aryReader.

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
  • Loading branch information
ShouruiSong committed Mar 10, 2025
1 parent 9b3a3bc commit 374fd77
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion core/runtime/vm/lepus/base_binary_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ class BaseBinaryReader : public BinaryReader {
#endif
tasm::CompileOptions compile_options_;

private:
std::vector<base::String> string_list_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
ElementBinaryReader::DeriveElementBinaryReader() {
auto reader =
std::make_unique<ElementBinaryReader>(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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class ElementBinaryReader : public LynxBinaryBaseCSSReader {
std::shared_ptr<ElementTemplateInfo> DecodeTemplatesInfoWithKey(
const std::string& key);

std::unique_ptr<ElementBinaryReader> DeriveElementBinaryReader();

protected:
// These are the APIs used for decoding data into fiber elements.
virtual bool DecodeElementChildrenSection(fml::RefPtr<FiberElement>& element,
Expand Down

0 comments on commit 374fd77

Please sign in to comment.