From 972d063ea1e7c11acdc2bf0f8f894f3e82b68357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Mondaini=20Calv=C3=A3o?= Date: Fri, 2 Oct 2026 15:43:34 -0300 Subject: [PATCH] fix(wasm): keep synchronous pathfinding off browser pthread pool --- src/floyd_warshall_optimized.zig | 8 +++++++- src/nav/floyd_warshall.zig | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/floyd_warshall_optimized.zig b/src/floyd_warshall_optimized.zig index 41491af..11c9c33 100644 --- a/src/floyd_warshall_optimized.zig +++ b/src/floyd_warshall_optimized.zig @@ -9,6 +9,7 @@ //! source-destination queries. const std = @import("std"); +const builtin = @import("builtin"); const INF: u32 = std.math.maxInt(u32); @@ -223,7 +224,12 @@ pub fn FloydWarshallOptimized(comptime config: Config) type { /// Run the Floyd-Warshall algorithm to compute all shortest paths pub fn generate(self: *Self) void { - if (config.parallel and self.size > 64) { + // Browser pthread pools are shared with persistent engine workers. + // This synchronous spawn/join algorithm cannot reserve a worker + // budget there; CPU discovery also uses unsupported sysctlbyname + // in Zig 0.16's Emscripten libc implementation. Keep web on SIMD + // until pathfinding can use an asynchronous, budgeted job API. + if (config.parallel and !builtin.single_threaded and builtin.os.tag != .emscripten and self.size > 64) { self.generateParallel(); } else if (config.simd) { self.generateSimd(); diff --git a/src/nav/floyd_warshall.zig b/src/nav/floyd_warshall.zig index eea72b5..f8bb955 100644 --- a/src/nav/floyd_warshall.zig +++ b/src/nav/floyd_warshall.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const types = @import("types.zig"); const graph_mod = @import("graph.zig"); const zig_utils = @import("zig_utils"); @@ -15,7 +16,9 @@ const U32_INF: u32 = std.math.maxInt(u32); /// Optimized FW backend: SIMD + multi-threading via zig-utils. const FWOptimized = zig_utils.FloydWarshallOptimized(.{ - .parallel = true, + // The synchronous zig-utils implementation cannot reserve workers from + // the browser's shared pthread pool. Use SIMD on threaded web too. + .parallel = !builtin.single_threaded and builtin.os.tag != .emscripten, .simd = true, });