perf(compile): TPC 编译提速——并行 worker 满核 + vast 解析器热点优化

cProfile 分析(206s 全量重编译 TPV):~163s 为 ProcessPool 等待(16 核机器仅用 8 worker),vast.parse 35.9s(1231 次)为最大 Python 计算热点。

- Phase2Translator:4 处 n_workers 上限 8 → os.cpu_count()(16 核满负荷),并行翻译/llc 编译利用率翻倍
- vast/Tokenizer._PosInfo:isascii 快速路径 + 行索引增量查找(~300 万次调用,免每次 bisect+encode)
- vast/Tokenizer._EmitOp:运算符按首字符分组,58 万次调用从 42 项全表 startswith 降到 2-3 项
- vast/Tokenizer._ScanName:内联 _IsIdentPart(70 万次循环免函数调用)
- Projectrans/Utils:find_reachable 用 deque + 后缀索引替代 pop(0)/全表扫描;topological_sort 用反向邻接表 + heapq 替代每轮 sort+全图扫描
This commit is contained in:
TermiNexus committed 2026-08-17 18:56:55 +08:00
1 parent 5d93692baa
commit 58ce673f01
4 files changed
+101 -44

No files matched your search

+3 -2
View File
@@ -179,9 +179,10 @@ class Phase1Generator:
needed: set[str] = set()
dep_graph: dict[str, set[str]] = {}
queue: list[str] = list(imported_from_src)
from collections import deque
queue: deque[str] = deque(imported_from_src)
while queue:
mod_name: str = queue.pop(0)
mod_name: str = queue.popleft()
if mod_name in needed:
continue
if mod_name in include_file_map: