Skip to content

Commit 5bafcfc

Browse files
committed
fix: wasm32 performance calculate adapt earror
1 parent 2a1ff0a commit 5bafcfc

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ web-sys = { version = "0.3", features = ["Headers", "Request", "RequestInit", "R
5757
js-sys = { version = "0.3", optional = true }
5858
wasm-bindgen-futures = { version = "0.4", optional = true }
5959
serde-wasm-bindgen = { version = "0.6", optional = true }
60+
instant = { version = "0.1.13", features = ["wasm-bindgen"] }
6061

6162
# Configure dependencies differently for different targets
6263
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

src/worker.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::core::error::AnalysisError;
22
use crate::net::ProviderConfig;
33
use crate::{core::filter::IntelligentFilter, net::RemoteAnalyzer};
4+
use instant::Instant;
45
use std::collections::HashMap;
56
use wasm_bindgen::prelude::*;
67

@@ -51,8 +52,8 @@ impl Default for AnalysisOptions {
5152
struct WASMDebugInfo {
5253
total_languages: usize,
5354
total_files: usize,
54-
spend_time: u64,
5555
version: String,
56+
spend_time: u64,
5657
}
5758

5859
#[derive(serde::Serialize)]
@@ -129,8 +130,8 @@ fn create_wasm_result(
129130
debug_info: WASMDebugInfo {
130131
total_languages: analysis.language_analyses.len(),
131132
total_files: analysis.global_metrics.file_count,
132-
spend_time,
133133
version: VERSION.to_string(),
134+
spend_time,
134135
},
135136
}
136137
}
@@ -148,8 +149,8 @@ fn create_error_result(error: AnalysisError, url: String, spend_time: u64) -> WA
148149
debug_info: WASMDebugInfo {
149150
total_languages: 0,
150151
total_files: 0,
151-
spend_time,
152152
version: VERSION.to_string(),
153+
spend_time,
153154
},
154155
}
155156
}
@@ -159,8 +160,6 @@ pub async fn analyze_url(url: String, options: JsValue) -> Result<JsValue, JsVal
159160
let opts: AnalysisOptions = serde_wasm_bindgen::from_value(options)?;
160161
console(&format!("Starting analysis for URL: {}", url));
161162

162-
let start_time = std::time::Instant::now();
163-
164163
let mut analyzer = RemoteAnalyzer::new();
165164
analyzer.set_global_config(opts.to_provider_config());
166165

@@ -172,6 +171,7 @@ pub async fn analyze_url(url: String, options: JsValue) -> Result<JsValue, JsVal
172171
},
173172
}
174173

174+
let start_time = Instant::now();
175175
let result = match analyzer.analyze_url(&url).await {
176176
Ok(analysis) => {
177177
let result = create_wasm_result(&analysis, start_time.elapsed().as_secs());

0 commit comments

Comments
 (0)