Skip to content

Feature/optimization round 2 - #2

Open
LoveProgrammingMint wants to merge 3 commits into
XTY64XTY:masterfrom
LoveProgrammingMint:feature/optimization-round-2
Open

Feature/optimization round 2#2
LoveProgrammingMint wants to merge 3 commits into
XTY64XTY:masterfrom
LoveProgrammingMint:feature/optimization-round-2

Conversation

@LoveProgrammingMint

Copy link
Copy Markdown
Contributor

PR 标题

perf(feature-engineering): simplify ProHybrid and vectorize loops without changing output

PR 正文

目标

在上一个 PR 合并后的基础上,继续优化 Xdows-Model-Invoker 特征工程性能。保持特征维度与特征值不变,通过向量化/Span/unsafe 指针和算法简化降低耗时。

改动范围

本次 PR 仅包含 upstream/masterb1060ad)之后的 3 个提交:

  • debbefc perf(FeatureExtractor): Span-based APIs, unsafe block loops and Flash small-file shortcut
  • 2366cb4 refactor(ProHybrid): simplify to composed extractors with capped section entropy
  • d019094 feat(Caller): add -dumpfeatures mode for feature vector export

主要改动

1. ByteAnalysisHelper 底层加速

  • ByteClass 字节分类查找表替代逐字节 if/else
  • 熵计算改用 Math.Log2(p)
  • 频数统计用 stackalloc long[256] 替代堆分配。
  • Standard 全文件 256 B block 熵改用 unsafe 指针循环。
  • Flash 小文件(≤512 KB)直接复用原数组,避免 head/tail 拷贝。

2. ProHybridFeatureExtractor 简化

  • 删除约 400 行 RegionStats 分段单次遍历代码。
  • Pro 模式改为组合已优化的 FeatureExtractor + FlashFeatureExtractor + ProRawStatExtractor + ExtractStructuralFeatures
  • Section 熵从“均匀抽样 128 KB”改为 min(实际大小, 128 KB) 截断顺序计算,成本可预测。

3. 调试工具

  • Caller 新增 -dumpfeatures <file> <out.csv>,用于导出 Standard/Flash/Pro 三组特征向量,方便验证特征一致性。

性能对比(Debug 构建,相对 upstream/master

文件 模式 优化前 优化后 差值 变化
kernel32.dll (836 KB) Standard 14.06 ms 13.72 ms -0.34 ms -2.4%
kernel32.dll (836 KB) Flash 5.16 ms 4.73 ms -0.43 ms -8.3%
kernel32.dll (836 KB) Pro 85.68 ms 19.42 ms -66.26 ms -77.3%
onnxruntime.dll (10.5 MB) Standard 182.50 ms 173.39 ms -9.11 ms -5.0%
onnxruntime.dll (10.5 MB) Flash 5.34 ms 4.59 ms -0.75 ms -14.0%
onnxruntime.dll (10.5 MB) Pro 551.62 ms 171.80 ms -379.82 ms -68.9%

精度影响

使用 -dumpfeatures 对比 kernel32.dllonnxruntime.dll 的 Standard/Flash/Pro 三组特征向量:

  • 变化维度:0
  • 最大绝对差:0
  • 平均绝对差:0

即本次优化在提速的同时完全未改变特征输出,对模型精度无影响。

… small-file shortcut

- ComputeByteHistogram32/ComputeBlockEntropyStats accept Span/ReadOnlySpan to avoid array copies.

- Standard block-entropy and ByteAnalysisHelper block stats use unsafe pointer loops to skip bounds checks.

- ParsePeHeader works over ReadOnlySpan<byte>.

- Flash path returns early with a single head region when file size <= FlashRegionSize.
…ion entropy

- Revert ProHybrid from single-pass unified RegionStats back to calling optimized Standard/Flash/RawStat extractors.

- Replace section entropy sampling with min(actual, 128KB) truncation for predictable cost.

- Removes ~400 lines of complex segmented stat bookkeeping.
@LoveProgrammingMint

Copy link
Copy Markdown
Contributor Author

This will be my last commit

@LoveProgrammingMint

Copy link
Copy Markdown
Contributor Author

此次提交不签署MINT协议,自动签署源仓库所签署的协议,保留原始作署权

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant