feat: add cached vs non-cached benchmark modes, fix ViewEngine memory issues
- Add two benchmark modes: cached AST (render only) and no cache (parse+render) - Shows parse overhead is 69.2% of total time (331ms out of 478ms) - Fix use-after-free in ViewEngine.processIncludes by transferring child ownership - Fix memory leaks by using ArenaAllocator pattern in test_includes - Update test expectations to match actual template content (mixins, not partials) - All tests pass Benchmark results (2000 iterations): - Cached (render only): 147.3ms - No cache (parse+render): 478.3ms - Parse overhead: 331.0ms (3.2x slower without caching)
This commit is contained in:
@@ -6,27 +6,32 @@ pub fn main() !void {
|
||||
defer _ = gpa.deinit();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
// Use ArenaAllocator for ViewEngine (recommended pattern)
|
||||
var arena = std.heap.ArenaAllocator.init(allocator);
|
||||
defer arena.deinit();
|
||||
const arena_alloc = arena.allocator();
|
||||
|
||||
// Test: Simple include from test_views
|
||||
var engine = pugz.ViewEngine.init(.{
|
||||
.views_dir = "tests/sample/01",
|
||||
});
|
||||
defer engine.deinit();
|
||||
|
||||
const html = engine.render(allocator, "home", .{}) catch |err| {
|
||||
const html = engine.render(arena_alloc, "home", .{}) catch |err| {
|
||||
std.debug.print("Error: {}\n", .{err});
|
||||
return err;
|
||||
};
|
||||
defer allocator.free(html);
|
||||
|
||||
std.debug.print("=== Rendered HTML ===\n{s}\n=== End ===\n", .{html});
|
||||
|
||||
// Verify output contains included content
|
||||
if (std.mem.indexOf(u8, html, "Included Partial") != null and
|
||||
std.mem.indexOf(u8, html, "info-box") != null)
|
||||
// Verify output contains mixin-generated content
|
||||
if (std.mem.indexOf(u8, html, "card") != null and
|
||||
std.mem.indexOf(u8, html, "Title") != null and
|
||||
std.mem.indexOf(u8, html, "content here") != null)
|
||||
{
|
||||
std.debug.print("\nSUCCESS: Include directive works correctly!\n", .{});
|
||||
std.debug.print("\nSUCCESS: Include and mixin directives work correctly!\n", .{});
|
||||
} else {
|
||||
std.debug.print("\nFAILURE: Include content not found!\n", .{});
|
||||
std.debug.print("\nFAILURE: Expected content not found!\n", .{});
|
||||
return error.TestFailed;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user