Skip to content

Commit 3501320

Browse files
committed
Plugin: Use OnceCell instead of Lazy_statics
- Using OnceCell improved the performance and make it similar to resource as interface approach
1 parent c1b74b7 commit 3501320

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

application/apps/indexer/wasm_plugin/client-inter/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

application/apps/indexer/wasm_plugin/client-inter/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ dlt-core = { path = "../../../../../../dlt-core" }
1414
serde = "1.0.201"
1515
chrono = "0.4.38"
1616
humantime = "2.1.0"
17-
lazy_static = "1.4.0"
1817

1918
[lib]
2019
crate-type = ["cdylib"]

application/apps/indexer/wasm_plugin/client-inter/src/dlt_parser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use dlt_core::{dlt, parse::dlt_message};
1111

1212
use self::{formattable_msg::FormattableMessage, ft_scanner::FtScanner};
1313

14+
#[derive(Debug)]
1415
pub struct DltParser {
1516
pub with_storage_header: bool,
1617
ft_scanner: Mutex<FtScanner>,

application/apps/indexer/wasm_plugin/client-inter/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
mod dlt_parser;
22

3+
use std::sync::OnceLock;
4+
35
use dlt_parser::DltParser;
46
use exports::host::indexer::parse_client_inter::Guest;
57
use host::indexer::parsing::{Error, ParseReturn};
6-
use lazy_static::lazy_static;
78
use wit_bindgen::generate;
89

910
generate!({
@@ -14,23 +15,24 @@ generate!({
1415
},
1516
});
1617

17-
lazy_static! {
18-
static ref PARSER: DltParser = DltParser::new();
19-
}
18+
static PARSER: OnceLock<DltParser> = OnceLock::new();
2019

2120
struct Component;
2221

2322
impl Guest for Component {
2423
fn init(configs: _rt::String) -> Result<(), Error> {
25-
Ok(PARSER.init(configs))
24+
let parser = DltParser::new();
25+
parser.init(configs);
26+
PARSER.set(parser).unwrap();
27+
Ok(())
2628
}
2729

2830
fn parse(data: _rt::Vec<u8>, timestamp: Option<u64>) -> _rt::Vec<Result<ParseReturn, Error>> {
29-
PARSER.parse(data, timestamp)
31+
PARSER.get().unwrap().parse(data, timestamp)
3032
}
3133

3234
fn parse_res(data: _rt::Vec<u8>, timestamp: Option<u64>) {
33-
PARSER.parse_res(data, timestamp)
35+
PARSER.get().unwrap().parse_res(data, timestamp)
3436
}
3537
}
3638

application/apps/indexer/wasm_plugin/host/wit/indexer.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ world parse {
5656
// Parse client using an interface without resources.
5757
// With this approach, the host doesn't need to instantiate the parser but the parser
5858
// doesn't have a reference to itself on the method and must save it's state using statics
59-
// This approach is less performant than the ratio `1.04`
59+
// This approach's perfrmance is similar to the parser interface as resource approach
6060
interface parse-client-inter {
6161
use parsing.{error, parse-return};
6262

0 commit comments

Comments
 (0)