performance improvement

This commit is contained in:
mii443
2025-05-06 22:43:35 +09:00
parent 993ebc0254
commit a1a1c1ab06
4 changed files with 22 additions and 24 deletions

View File

@ -1,12 +1,8 @@
use std::path::PathBuf;
use azookey_binding::Candidate;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use tracing::info;
use crate::SELF_EXE_PATH;
use super::IpcMessage;
pub struct AzookeyConversionClient {
@ -41,16 +37,8 @@ impl AzookeyConversionClient {
pub fn request_candidates(&mut self, context: &str) -> Vec<Candidate> {
info!("Requesting candidates for context: {}", context);
let self_exe_path = PathBuf::from(SELF_EXE_PATH.read().unwrap().as_str());
let weight_path = self_exe_path
.parent()
.unwrap()
.join("ggml-model-Q5_K_M.gguf");
self.sender
.send(IpcMessage::RequestCandidates(
context.to_string(),
weight_path.to_string_lossy().to_string(),
))
.send(IpcMessage::RequestCandidates(context.to_string()))
.unwrap();
loop {
match self.receiver.recv() {

View File

@ -12,7 +12,7 @@ pub enum IpcMessage {
Sender(IpcSender<IpcMessage>),
ResetComposingText,
InsertAtCursorPosition(String),
RequestCandidates(String, String),
RequestCandidates(String),
Candidates(Vec<Candidate>),
End,
}

View File

@ -1,10 +1,12 @@
use std::{collections::HashMap, sync::LazyLock};
use std::{collections::HashMap, path::PathBuf, sync::LazyLock};
use azookey_binding::{Candidate, ComposingText, KanaKanjiConverter};
use ipc_channel::ipc::IpcOneShotServer;
use itertools::Itertools;
use platform_dirs::AppDirs;
use crate::SELF_EXE_PATH;
use super::IpcMessage;
static SIGNMAP: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
@ -116,6 +118,20 @@ impl AzookeyConversionServer {
let (a, _) = self.server.accept().unwrap();
let mut sender = None;
let app_dirs = AppDirs::new(Some("vrclipboard-ime"), false).unwrap();
let path = app_dirs
.config_dir
.join("AzooKeyDictionary\\AzooKeyDictionary\\Dictionary");
let extract_path = path.to_str().unwrap();
let self_exe_path = PathBuf::from(SELF_EXE_PATH.read().unwrap().as_str());
let weight_path = self_exe_path
.parent()
.unwrap()
.join("ggml-model-Q5_K_M.gguf")
.to_string_lossy()
.to_string();
loop {
match a.recv() {
Ok(IpcMessage::Sender(s)) => {
@ -128,12 +144,7 @@ impl AzookeyConversionServer {
let text = Self::pre_process_text(&text);
self.composing_text.insert_at_cursor_position(&text);
}
Ok(IpcMessage::RequestCandidates(context, weight_path)) => {
let app_dirs = AppDirs::new(Some("vrclipboard-ime"), false).unwrap();
let path = app_dirs
.config_dir
.join("AzooKeyDictionary\\AzooKeyDictionary\\Dictionary");
let extract_path = path.to_str().unwrap();
Ok(IpcMessage::RequestCandidates(context)) => {
let candidates = self.azookey_converter.request_candidates(
&self.composing_text,
&context,

View File

@ -186,15 +186,14 @@ pub static SELF_EXE_PATH: Lazy<RwLock<String>> = Lazy::new(|| RwLock::new(String
async fn main() {
let args = std::env::args().collect::<Vec<_>>();
SELF_EXE_PATH.write().unwrap().push_str(&args[0]);
if args.contains(&"server".to_string()) {
let server = AzookeyConversionServer::new();
let server_name = &server.server_name;
println!("${}$", server_name);
server.server_loop();
return;
} else {
println!("Args: {:?}", args);
SELF_EXE_PATH.write().unwrap().push_str(&args[0]);
}
let server_name = start_server_process();