Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/floyd_warshall_optimized.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! source-destination queries.

const std = @import("std");
const builtin = @import("builtin");

const INF: u32 = std.math.maxInt(u32);

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/nav/floyd_warshall.zig
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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,
});

Expand Down
Loading