global: speed improvement part2

This commit is contained in:
nym21
2026-04-09 14:02:26 +02:00
parent 21a0226a19
commit 5a3e1b4e6e
24 changed files with 137 additions and 160 deletions

View File

@@ -189,8 +189,26 @@ impl AppState {
F: FnOnce(&brk_query::Query) -> brk_error::Result<T> + Send + 'static,
{
self.cached(headers, strategy, uri, "application/json", move |q, enc| {
let t0 = std::time::Instant::now();
let value = f(q)?;
Ok(enc.compress(Bytes::from(serde_json::to_vec(&value).unwrap())))
let t_query = t0.elapsed();
let json = serde_json::to_vec(&value).unwrap();
let t_json = t0.elapsed();
let json_len = json.len();
let compressed = enc.compress(Bytes::from(json));
let t_total = t0.elapsed();
if t_total.as_millis() > 100 {
eprintln!(
"[perf] query={:.1?} json={:.1?}({:.1}MB) compress={:.1?}({}) total={:.1?}",
t_query,
t_json - t_query,
json_len as f64 / 1_048_576.0,
t_total - t_json,
enc.as_str(),
t_total,
);
}
Ok(compressed)
})
.await
}