(refractor) timer and warm up query

This commit is contained in:
polv committed 2026-03-03 12:44:54 +07:00
1 parent 1b2ee0f691
commit d6f2b145c3
13 files changed
+294 -47

No files matched your search

+8
View File
@@ -38,6 +38,7 @@ impl Database {
PRAGMA jornal_mode = WAL;
PRAGMA synchronous = NORMAL;
PRAGMA foreign_keys = ON;
PRAGMA cache_size = -131072;
",
)?;
@@ -81,6 +82,13 @@ impl Database {
let uri = format!("file:{}?mode=ro&immutable=1", path);
conn.execute("ATTACH DATABASE ?1 AS yomitan", [uri])?;
conn.execute_batch(
r"
PRAGMA yomitan.mmap_size = 3000000000; -- 3_000_000_000
",
)?;
self.yomitan_attached.store(true, Ordering::Release);
}
+3 -1
View File
@@ -2,7 +2,7 @@ use rusqlite::{Result, params};
use serde::Serialize;
use crate::{
CJDicError,
CJDicError, Timer,
db::{Database, yomitan_writer::normalize_term},
};
@@ -35,6 +35,8 @@ impl YomitanDatabase {
limit: u32,
offset: u32,
) -> Result<Vec<YomitanRow>, CJDicError> {
let _timer = Timer::new(format!("search_yomitan: {} {}", q_term, q_reading));
let and_or = if q_term == q_reading { "OR" } else { "AND" };
let mut new_t = String::new();
+2 -9
View File
@@ -7,11 +7,10 @@ use std::{
collections::HashMap,
io::{Cursor, Read},
path::{Path, PathBuf},
time::Instant,
};
use zip::ZipArchive;
use crate::CJDicError;
use crate::{CJDicError, Timer};
fn blake3_hex(s: &str) -> String {
format!("{}", hash(s.as_bytes()))
@@ -274,8 +273,8 @@ impl YomitanWriter {
Callback: Fn(YomitanZipImportProgress),
{
let bundle_name = zip_file.file_name();
let _timer = Timer::new(format!("Importing {}", bundle_name));
let start_time = Instant::now();
self.conn.execute_batch("PRAGMA foreign_keys = off")?;
let cursor = Cursor::new(zip_file.bytes()?);
@@ -593,12 +592,6 @@ impl YomitanWriter {
tx.commit()?;
println!(
"Importing {} takes {:.2?}",
zip_file.file_name(),
start_time.elapsed()
);
self.conn.execute_batch(
"
PRAGMA foreign_keys = on;
+2
View File
@@ -1,10 +1,12 @@
mod db;
mod error;
mod service;
mod util;
pub use db::{YomitanRow, YomitanZipImportProgress, YomitanZipImportResult, ZipSource};
pub use error::CJDicError;
pub use service::AppService;
pub use util::Timer;
pub fn add(left: u64, right: u64) -> u64 {
left + right
+35
View File
@@ -0,0 +1,35 @@
#[cfg(debug_assertions)]
use std::time::Instant;
#[cfg(debug_assertions)]
pub struct Timer {
start: Instant,
label: String,
}
#[cfg(debug_assertions)]
impl Timer {
pub fn new(label: String) -> Self {
Self {
start: Instant::now(),
label,
}
}
}
#[cfg(debug_assertions)]
impl Drop for Timer {
fn drop(&mut self) {
println!("[{}] {:.2?}", self.label, self.start.elapsed())
}
}
#[cfg(not(debug_assertions))]
pub struct Timer;
#[cfg(not(debug_assertions))]
impl Timer {
pub fn new(_label: String) -> Self {
Self
}
}