镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 85dfd44

Browse files
committed
bench(frontend): add escaped identifier growth rows (#538)
Extend the parser-only frontend runner with 1,024, 2,048, and 4,096 strict parameter lists whose identifiers decode paramet\\u0065rN to parameterN. Source construction remains outside warmup and timing. Every parse validates the function declaration, parameter count, decoded prefix, and exact numeric suffix/index before summing all decoded name bytes. Frozen one-job checksums are 13,233, 27,569, and 56,241. The existing ordinary strict-parameter rows remain the allocation-free control. This is benchmark-first coverage only; flips 0 test262 cases.
1 parent 718cb12 commit 85dfd44

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

‎bench/frontend_parse.zig‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ fn workloadWidth(name: []const u8) !usize {
1616
if (std.mem.eql(u8, name, "representative_frontend_strict_params_1024")) return 1024;
1717
if (std.mem.eql(u8, name, "representative_frontend_strict_params_2048")) return 2048;
1818
if (std.mem.eql(u8, name, "representative_frontend_strict_params_4096")) return 4096;
19+
if (std.mem.eql(u8, name, "representative_frontend_escaped_identifiers_1024")) return 1024;
20+
if (std.mem.eql(u8, name, "representative_frontend_escaped_identifiers_2048")) return 2048;
21+
if (std.mem.eql(u8, name, "representative_frontend_escaped_identifiers_4096")) return 4096;
1922
if (std.mem.eql(u8, name, "representative_frontend_strings_1024")) return 1024;
2023
if (std.mem.eql(u8, name, "representative_frontend_strings_2048")) return 2048;
2124
if (std.mem.eql(u8, name, "representative_frontend_strings_4096")) return 4096;
@@ -40,12 +43,17 @@ fn isTaggedTemplateWorkload(name: []const u8) bool {
4043
return std.mem.eql(u8, name, "representative_frontend_templates_tagged_4096");
4144
}
4245

43-
fn strictFunctionSource(allocator: std.mem.Allocator, width: usize) ![]const u8 {
46+
fn isEscapedIdentifierWorkload(name: []const u8) bool {
47+
return std.mem.startsWith(u8, name, "representative_frontend_escaped_identifiers_");
48+
}
49+
50+
fn strictFunctionSource(allocator: std.mem.Allocator, width: usize, escaped: bool) ![]const u8 {
4451
var source: std.ArrayListUnmanaged(u8) = .empty;
4552
try source.appendSlice(allocator, "function strictWidth(");
4653
for (0..width) |index| {
4754
if (index != 0) try source.append(allocator, ',');
48-
try source.appendSlice(allocator, try std.fmt.allocPrint(allocator, "parameter{d}", .{index}));
55+
try source.appendSlice(allocator, if (escaped) "paramet\\u0065r" else "parameter");
56+
try source.appendSlice(allocator, try std.fmt.allocPrint(allocator, "{d}", .{index}));
4957
}
5058
try source.appendSlice(allocator, "){\"use strict\";return 7;}");
5159
return source.items;
@@ -106,7 +114,16 @@ fn parseOnce(allocator: std.mem.Allocator, source: []const u8, workload: []const
106114
return checksum;
107115
}
108116
if (declaration.* != .func_decl) return error.InvalidProgram;
109-
return declaration.func_decl.params.len + 7;
117+
if (!isEscapedIdentifierWorkload(workload)) return declaration.func_decl.params.len + 7;
118+
var checksum = declaration.func_decl.params.len + 7;
119+
for (declaration.func_decl.params, 0..) |param, index| {
120+
if (param.name.len < "parameter".len or !std.mem.eql(u8, param.name[0.."parameter".len], "parameter"))
121+
return error.InvalidProgram;
122+
if (try std.fmt.parseUnsigned(usize, param.name["parameter".len..], 10) != index)
123+
return error.InvalidProgram;
124+
checksum += param.name.len;
125+
}
126+
return checksum;
110127
}
111128

112129
fn runJobs(allocator: std.mem.Allocator, source: []const u8, jobs: usize, workload: []const u8) !usize {
@@ -140,7 +157,7 @@ pub fn main(init: std.process.Init) !void {
140157
isTaggedTemplateWorkload(workload),
141158
)
142159
else
143-
try strictFunctionSource(init.arena.allocator(), width);
160+
try strictFunctionSource(init.arena.allocator(), width, isEscapedIdentifierWorkload(workload));
144161
for (0..warmup_calls) |_| _ = try runJobs(init.gpa, source, @max(@as(usize, 1), jobs / 10), workload);
145162

146163
var stdout_buffer: [4096]u8 = undefined;

0 commit comments

Comments
 (0)