Skip to content

Commit bcea934

Browse files
ZhaoChaoqunclaude
andcommitted
perf: use dynamic thread count for FunASR and QwenASR inference
FunASR Nano LLM now uses activeProcessorCount (all CPU cores) instead of hardcoded 1, reducing flush latency from ~11s to ~0.5s on M4. QwenASR numThreads defaults to 0 (auto-detect by Rust runtime). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e8484cc commit bcea934

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Sources/FunASRNanoLLMRecognizer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class FunASRNanoLLMRecognizer {
4343
config.model_config.funasr_nano.top_p = 0.8
4444
config.model_config.funasr_nano.seed = 42
4545

46-
config.model_config.num_threads = 1
46+
let threads = ProcessInfo.processInfo.activeProcessorCount
47+
config.model_config.num_threads = Int32(threads)
48+
logger.info("FunASRNanoLLMRecognizer: num_threads=\(threads)")
4749
config.model_config.debug = 0
4850
config.model_config.provider = cStrings.makeCString("cpu")
4951
config.model_config.model_type = cStrings.makeCString("")

Sources/QwenASRRecognizer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class QwenASRStreamRecognizer {
99
private var engine: OpaquePointer? // QwenAsrEngine*
1010
private var streamState: OpaquePointer? // QwenAsrStreamState*
1111

12-
init?(modelDir: String, numThreads: Int32 = 4) {
12+
init?(modelDir: String, numThreads: Int32 = 0) {
1313
logger.info("QwenASRStreamRecognizer: 开始初始化...")
1414
logger.debug("模型目录: \(modelDir, privacy: .public)")
1515

0 commit comments

Comments
 (0)