From e7f47735edeaa4842b8da78654780035dfc78a0c Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 14 Sep 2026 08:26:18 +0800 Subject: [PATCH] =?UTF-8?q?perf(callgen):=20find=5Ffunc=5Fin=5Fmodule=20?= =?UTF-8?q?=E4=BB=A5=20function=5Fget=5Fname=5Flen=20=E6=9B=BF=E4=BB=A3=20?= =?UTF-8?q?strlen=20=E7=83=AD=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 第二趟后缀匹配对每个函数节点调用 strlen(cur_name)(实测 2373 万次、占全程序 strlen 73.7%)改为读取 Function.NameLen;两处替换点:CallGenBase 约 563 与 597。 并在外部函数返回类型白名单登记 function_get_name_len 返回 i64(CSizeT),避免 stub 未注入时按默认 i32 导致签名不一致。匹配语义与返回顺序不变。 --- App/lib/core/Gen/Call/CallGenBase.vp | 10 +++++++--- App/lib/core/Gen/Call/CallGenLib.vp | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/App/lib/core/Gen/Call/CallGenBase.vp b/App/lib/core/Gen/Call/CallGenBase.vp index 41801fb..07e040b 100644 --- a/App/lib/core/Gen/Call/CallGenBase.vp +++ b/App/lib/core/Gen/Call/CallGenBase.vp @@ -556,9 +556,11 @@ class CallGenBase: # (mangled 模块级函数名含且只含一个 '.'),不匹配 # "{sha1}.Class.method" 等方法名。是否 IsDeclared==0 均可返回: # 前向 declare 与 define 同名同符号。只在 owner_sha1 提供且尚未 - # 命中时计算,避免多做一次 strlen。 + # 命中时计算,避免多做一次名字长度读取。 if owner_sha1 is not None and mangle_hit is None: - cur_len_o: sizet = string.strlen(cur_name) + # 名字长度改取 Function.NameLen(创建时一次算好),免去对热链 + # 每个节点重复 strlen(cur_name)(全程序 strlen 热点来源)。 + cur_len_o: sizet = llvmlite.function_get_name_len(cur) if cur_len_o == 17 + name_len: if string.strncmp(cur_name, owner_sha1, 16) == 0 and cur_name[16] == '.': suffix_start_o: sizet = cur_len_o - name_len @@ -590,7 +592,9 @@ class CallGenBase: while cur is not None: cur_name2: str = llvmlite.function_get_name(cur) if cur_name2 is not None: - cur_len: sizet = string.strlen(cur_name2) + # 名字长度改取 Function.NameLen(创建时一次算好),免去热链上 + # 每个节点重复 strlen(cur_name2);与 strlen(Name) 恒等,不改匹配语义。 + cur_len: sizet = llvmlite.function_get_name_len(cur) if cur_len > name_len + 1: suffix_start: sizet = cur_len - name_len if cur_name2[suffix_start - 1] == '.': diff --git a/App/lib/core/Gen/Call/CallGenLib.vp b/App/lib/core/Gen/Call/CallGenLib.vp index bc70ac8..e6868cb 100644 --- a/App/lib/core/Gen/Call/CallGenLib.vp +++ b/App/lib/core/Gen/Call/CallGenLib.vp @@ -467,6 +467,12 @@ class CallGenLib(CallGenBase.CallGenBase): return llvmlite.Int64(pool) if string.strcmp(func_name, "atoll") == 0: return llvmlite.Int64(pool) + # llvmlite 函数名长度访问器返回 t.CSizeT(i64):stub/vpi 尚未注入时若 + # 默认 i32 会与 declare 的 i64 签名不一致(call i32 vs declare i64), + # 与 function_get_name 指针白名单同理须登记返回类型。 + if string.strcmp(bare_name, "function_get_name_len") == 0 or \ + string.strcmp(func_name, "function_get_name_len") == 0: + return llvmlite.Int64(pool) # 返回 double 的函数 if string.strcmp(func_name, "atof") == 0: