Repository navigation
Conversation
This was referenced Nov 26, 2026
sinspired
force-pushed
the
perf/mihomoProfile_process
branch
from
November 27, 2026 05:21
3156114 to
c7a5fe0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
目前在处理带有
process操作列表的mihomoConfig/mihomoProfile文件时,整个流程会反复执行多次YAML.safeDump→YAML.safeLoad往返:prepareMihomoProfileContent先把拼装好的config对象safeDump成 YAML 字符串;AddProxiesFromSubscriptionOperator再把$contentsafeLoad回对象,写入proxies后又safeDump一次;ScriptOperator(不管是 YAML 合并补丁,还是 JSmain(config)覆写脚本)又会把$contentsafeLoad回对象,改完再safeDump一次。节点数比较多(比如上千个节点)或者覆写规则比较大时,每多一步操作就要重走一遍纯 JS 的 YAML 解析和生成,在低功耗设备上的 CPU 开销比较明显。
改动内容
本次只改了
backend/src/restful/sync.js和backend/src/core/proxy-utils/processors/index.js两个文件,在带process操作的mihomoProfile流程中增加内部惰性状态(MIHOMO_CONFIG_STATE_KEY),让中间步骤直接复用内存里的config对象:sync.js:prepareMihomoProfileContent增加内部参数returnConfig,支持直接返回内存里的config对象;produceArtifact通过createMihomoFileInput构造带$content/$files[0]惰性 getter/setter 的输入对象,只有真正读取$content或$files时才按需执行safeDump。processors/index.js:cloneFileInput在执行操作前做浅拷贝时保留MIHOMO_CONFIG_STATE_KEY的惰性状态,不影响原有隔离行为;AddProxiesFromSubscriptionOperator和ScriptOperator(YAML 合并以及未直接引用$content/$files的main(config)脚本)优先直接读写state.config,跳过中间的safeLoad和safeDump,最后只统一序列化一次。兼容性说明
$content或$files,或者外部直接调用ProxyUtils.process传入普通对象,惰性 getter 会自动触发safeDump;手动给$content赋值时也会自动清空state.config,外部表现和原版完全一致;produceType === 'raw'以及没有配置process操作的文件不走这套惰性对象,行为没有任何变化。测试情况
Mihomo-Rules覆写脚本测试,各步骤之间不再重复做 YAML 解析与序列化;在纯 JSjs-yaml路径下,拉取api/file/mihomo的耗时从约10.3s降到了6.3s。替代的 PR
本 PR 已覆盖并替代以下两个 PR。相比之前的实现,本次改动范围更小,测试结果也已验证,主分支已有优化代码,可以关闭: