Skip to content

Commit

Permalink
fix(perf/wasm): avoid scopes for latency logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-melnychuk committed Oct 31, 2024
1 parent c1dfafe commit 97f23b5
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,41 +110,27 @@ impl EthereumClient {
let block_number = u64::from_be_bytes(block_number);

#[cfg(target_arch = "wasm32")]
{
let ms = now.elapsed().as_millis();
web_sys::console::log_1(
&format!("call to stateBlockNumber completed in {ms} ms")
.into(),
);
#[allow(unused_variables)]
let now = Instant::now();
}
log_latency("stateBlockNumber", &now);

#[cfg(target_arch = "wasm32")]
let now = Instant::now();

let data = 0x382d83e3u32.to_be_bytes(); // keccak("stateBlockHash()")
let block_hash: H256 =
self.call(&data, tag).await.context("helios: state block hash")?;

#[cfg(target_arch = "wasm32")]
{
let ms = now.elapsed().as_millis();
web_sys::console::log_1(
&format!("call to stateBlockHash completed in {ms} ms").into(),
);
#[allow(unused_variables)]
let now = Instant::now();
}
log_latency("stateBlockHash", &now);

#[cfg(target_arch = "wasm32")]
let now = Instant::now();

let data = 0x9588eca2u32.to_be_bytes(); // keccak("stateRoot()")"
let root: H256 =
self.call(&data, tag).await.context("helios: state root")?;

#[cfg(target_arch = "wasm32")]
{
let ms = now.elapsed().as_millis();
web_sys::console::log_1(
&format!("call to stateRoot completed in {ms} ms").into(),
);
}
log_latency("stateRoot", &now);

tracing::debug!(block_number, ?block_hash, ?root, "starknet state");

Expand Down Expand Up @@ -175,6 +161,13 @@ impl EthereumClient {
}
}

#[cfg(target_arch = "wasm32")]
fn log_latency(method: &str, instant: &Instant) {
let millis = instant.elapsed().as_millis();
let message = format!("call to {method} completed in {ms} ms");
web_sys::console::log_1(&message.into());
}

async fn get_client(
rpc: &str,
network: Network,
Expand Down

0 comments on commit 97f23b5

Please sign in to comment.