From ddb2554fff073eed0b73a43825b2c007c895bc4d Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 30 Oct 2026 05:58:13 -0300 Subject: replica: a far client's content cache and zstd: the session lists its join's blobs by BLAKE3 hash first (wire 16 `blobs`), the client finds each in the core it leaves or on disk ($XDG_CACHE_HOME/pardes/blobs, hashed again on load, a bad file a miss, the least recently used evicted past 1 GiB) and asks for the rest (`want`), and everything after the welcome goes in zstd envelopes (level 6 over 8 MiB for the join, an undo snapshot being a near copy of its text, then level 3), so `ssh -C` leaves the default command; a far client (through ssh, or PARDES_REPLICA_FAR) keeps what it was sent and, at its end, what it made; a hangup ends a remote client the normal way; through the box a client holding the blobs is drawn in 2.4 s where main took 7.0 to 11.9, and a first join of a session with undo in 7.1 s where main took 11.9; libzstd 1.5.7 vendored, its allocations on c_heap, a second copy refused by shared-libs-check; tests for the cache's verify-on-load, its eviction and a far join's blobs sent once; test/daemon.py's far clients Co-Authored-By: Claude Opus 5.5 --- build.zig | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'build.zig') diff --git a/build.zig b/build.zig index c0235e41..5e88ef68 100644 --- a/build.zig +++ b/build.zig @@ -964,6 +964,44 @@ pub fn build(b: *std.Build) void { if (sources != 1) @panic("zstbi's build no longer compiles one C file: redo its patch in build.zig"); }; + // One zstd (docs/shared-libs.md): a far replica's stream, compressed by + // its session and read by its client (src/replica.zig). The library's + // compressor and decompressor alone, single-threaded and without its + // x86 assembly, each context made with ZSTD_customMem over c_heap; of + // its block compressors only those of levels 3 (dfast) and 6 (lazy), + // the two replica.zig asks for, and its unused functions dropped at + // link. Zig's std has a decompressor, but no compressor. + if (!freestanding_core) { + const dep = b.dependency("zstd", .{}); + const zstd = b.addLibrary(.{ + .name = "zstd", + .root_module = b.createModule(.{ .target = target, .optimize = c_optimize, .link_libc = true }), + .linkage = .static, + }); + zstd.root_module.addCSourceFiles(.{ + .root = dep.path("lib"), + .files = &.{ + "common/debug.c", "common/entropy_common.c", "common/error_private.c", + "common/fse_decompress.c", "common/pool.c", "common/threading.c", + "common/xxhash.c", "common/zstd_common.c", "compress/fse_compress.c", + "compress/hist.c", "compress/huf_compress.c", "compress/zstd_compress.c", + "compress/zstd_compress_literals.c", "compress/zstd_compress_sequences.c", "compress/zstd_compress_superblock.c", + "compress/zstd_double_fast.c", "compress/zstd_fast.c", "compress/zstd_lazy.c", + "compress/zstd_ldm.c", "compress/zstd_opt.c", "compress/zstd_preSplit.c", + "decompress/huf_decompress.c", "decompress/zstd_ddict.c", "decompress/zstd_decompress.c", + "decompress/zstd_decompress_block.c", + }, + .flags = &.{ + "-DXXH_NAMESPACE=ZSTD_", "-DZSTD_DISABLE_ASM", "-DZSTD_LEGACY_SUPPORT=0", + "-DDEBUGLEVEL=0", "-DZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", + "-DZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "-DZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", + }, + }); + zstd.link_function_sections = true; + zstd.link_data_sections = true; + for (core_mods) |m| m.linkLibrary(zstd); + } + // One call per module instead of one line per module per dependency, and // BEFORE the fold below, which reads what these imports put in the table. for (core_mods) |m| wireCore(m, .{ -- cgit v1.3