-
Notifications
You must be signed in to change notification settings - Fork 45
perf(instance): update modlist translate logic to improve retrieve speed #1106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the mod list translation retrieval process to improve performance through concurrency control and enhanced caching. The changes focus on reducing redundant translation lookups and preventing resource exhaustion.
Key changes:
- Implements semaphore-based concurrency control to limit parallel mod processing tasks
- Refactors cache logic to use file names as keys instead of file paths, improving cache hit rate
- Consolidates cache persistence to a single write operation at the end of mod list retrieval
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src-tauri/src/lib.rs | Initializes and manages the mod translation cache at application startup |
| src-tauri/src/instance/helpers/mods/common.rs | Refactors cache structure, removes async file I/O functions, switches cache key from file path to file name |
| src-tauri/src/instance/constants.rs | Adds constants for cache expiry time and cache file name |
| src-tauri/src/instance/commands.rs | Implements semaphore for concurrency control, consolidates cache updates to single write operation |
| }; | ||
| let file_path = mod_info.file_path.to_string_lossy().to_string(); | ||
| let cache = load_local_mod_translations_cache(app).await; | ||
| let file_name = mod_info.file_name.clone(); |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary clone operation. The file_name field is already a String and is only used for lookups and logging. Consider borrowing it instead of cloning, or use &mod_info.file_name directly in subsequent operations.
src-tauri/src/instance/commands.rs
Outdated
| )); | ||
| for path in mod_paths { | ||
| let task = tokio::spawn(async move { get_mod_info_from_jar(&path).await.ok() }); | ||
| let permit = semaphore.clone().acquire_owned().await.unwrap(); |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using unwrap() on semaphore acquisition will panic if the semaphore is closed or if there's an error. Consider using proper error handling with ? operator or providing a meaningful error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot 说的在理,这里做一下错误返回而不是 panic
src-tauri/src/instance/commands.rs
Outdated
| let permit = semaphore.clone().acquire_owned().await.unwrap(); | ||
| let task = tokio::spawn(async move { |
Copilot
AI
Oct 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using unwrap() on semaphore acquisition will panic if the semaphore is closed or if there's an error. Consider using proper error handling with ? operator or providing a meaningful error message.
| let permit = semaphore.clone().acquire_owned().await.unwrap(); | |
| let task = tokio::spawn(async move { | |
| let task = tokio::spawn(async move { | |
| let permit = semaphore.clone().acquire_owned().await.ok()?; |
src-tauri/src/instance/constants.rs
Outdated
| @@ -1 +1,3 @@ | |||
| pub const INSTANCE_CFG_FILE_NAME: &str = "sjmclcfg.json"; | |||
| pub const CACHE_EXPIRY_HOURS: u64 = 24; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这两个 const 放在这就有点意义混淆了,建议增加 TRANSLATION_ 前缀
src-tauri/src/instance/commands.rs
Outdated
| )); | ||
| for path in mod_paths { | ||
| let task = tokio::spawn(async move { get_mod_info_from_jar(&path).await.ok() }); | ||
| let permit = semaphore.clone().acquire_owned().await.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot 说的在理,这里做一下错误返回而不是 panic
src-tauri/src/instance/commands.rs
Outdated
| let task = tokio::spawn(async move { get_mod_info_from_jar(&path).await.ok() }); | ||
| let permit = semaphore.clone().acquire_owned().await.unwrap(); | ||
| let task = tokio::spawn(async move { | ||
| info!("Processing mod: {}", path.display()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log 信息请改为:Load mod info from jar: {}
下面那个请改为:
log::debug!("Load mod info from dir: {}", path.display())
(可以不用 use log,直接 log::info!, log::debug!,更明显说明这是 logger 提供的方法,否则 error! 容易有误解)
|
话说这个translation cache json大小大吗? |
我装了五个大整合包后会有点大的,会到400KB |
会影响启动时间吗 有点好奇 |
基本没有捏 |
|
可以缓解 #1100 |
Checklist
This PR is a ..
Related Issues
Description
Additional Context