From 5b8cf6f66e367192090350c9129fa341edfc9343 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 16 Nov 2026 23:00:19 -0300 Subject: Compute abi.hash's layout half once per abi change, not in every compile The comptime walk over the shared types cost about half a second of every sketch library's compile. abi_hash.zig runs it at build time, once per change of the abi sources (watched like any input), and build.zig hands the number to host and sketches as the module abi_hash; abi.hash folds in the build as before. The value is the walk's own, computed for the build machine in Debug. --- src/abi.zig | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/abi.zig') diff --git a/src/abi.zig b/src/abi.zig index 33f7cd6..9154539 100644 --- a/src/abi.zig +++ b/src/abi.zig @@ -815,17 +815,22 @@ pub const Sketch = struct { }; }; -/// Layout hash of everything above, and of `build`. Changes whenever a shared -/// type does, or the compiler, backend or optimize mode: Zig's own calling -/// convention, which `Host.VTable` and every `std.mem.Allocator` use, differs -/// between backends and modes. -pub const hash: u64 = blk: { +/// `layout_hash` and `build`: changes whenever a shared type does, or the +/// compiler, backend or optimize mode, since Zig's own calling convention +/// (`Host.VTable`, every `std.mem.Allocator`) differs between them. +/// `layout_hash` costs half a second of comptime, so build.zig has +/// `abi_hash.zig` compute it once per change of these files and hands it +/// over as the module `abi_hash`, instead of every sketch's compile doing it. +pub const hash: u64 = std.hash.Wyhash.hash(@import("abi_hash").layout, build); + +/// Hash of every shared type's name and layout. +pub const layout_hash: u64 = blk: { @setEvalBranchQuota(1_000_000); var h: u64 = 0; for (.{ Rect, Color, BlendMode, Corners, Event, Mode, Stream, Input, Image, Audio, Cursor, Voice, Command, gpu.Pass, gpu.Pipeline, gpu.Draw, gpu.Dispatch, gpu.PostProcess, Host, Host.VTable, Context, Field, Layout, Info, Memory, Sketch }) |T| { h = std.hash.Wyhash.hash(h, @typeName(T) ++ layout.signature(T)); } - break :blk std.hash.Wyhash.hash(h, build); + break :blk h; }; /// The compiler, backend and mode of this build, exported by libraries as -- cgit v1.3