jukebox
All repositories: gitoria
2.8 KB
// Compare existing update/CAS/delete with before-image capture on a small// tests/mpackdb shape. ReleaseFast; fresh store per sample; no HL event overhead.const std = @import("std");const engine = @import("engine.zig");const mp = @import("msgpack.zig");const linux = std.os.linux;fn ns() i128 {var ts: linux.timespec = undefined;_ = linux.clock_gettime(linux.CLOCK.MONOTONIC, &ts);return @as(i128, ts.sec) * 1000000000 + ts.nsec;}pub fn main(init: std.process.Init) !void {var args = std.process.Args.Iterator.init(init.minimal.args);_ = args.next();const root = args.next().?;const a = init.gpa;for (0..3) |sample| {for ([_]engine.Db.MutationOp{ .update, .compareAndSet, .delete }) |op| {for ([_]bool{ false, true }) |capture| {const path = try std.fmt.allocPrint(a, "{s}/{d}-{s}-{any}.db", .{root, sample, @tagName(op), capture});defer a.free(path);const db = try engine.Db.open(a, path, .{ .primary_key = "id", .indexes = &.{"!email"}, .compact = false });defer db.close();var memory = std.heap.ArenaAllocator.init(a);defer memory.deinit();var entries = [_]mp.Entry{.{ .key = .{ .str = "id" }, .value = .{ .str = "counter" } },.{ .key = .{ .str = "email" }, .value = .{ .str = "counter@x" } },.{ .key = .{ .str = "seq" }, .value = .{ .number = 1 } },};const rec: mp.Value = .{ .map = &entries };_ = try db.insert(memory.allocator(), rec, false);const t = ns();for (0..500) |_| {_ = memory.reset(.retain_capacity);const arena = memory.allocator();if (op == .delete) _ = db.insert(arena, rec, false) catch |e| switch (e) { error.DuplicateKey => engine.Db.InsertResult{ .pk_str = "counter" }, else => return e };if (capture) {const result = try db.mutate(arena, op, .{ .str = "counter" }, rec, .{ .map = &.{} });if (result.prev.items.len != 1) return error.MissingBeforeImage;} else switch (op) {.update => { _ = try db.updatePk(arena, .{ .str = "counter" }, rec); },.compareAndSet => { _ = try db.compareAndSet(arena, .{ .str = "counter" }, rec, .{ .map = &.{} }); },.delete => { var old: std.ArrayList(mp.Value) = .empty; _ = try db.deletePk(arena, .{ .str = "counter" }, &old); },else => unreachable,}}std.debug.print("sample={d} op={s} capture={any} rounds=500 ns_per_op={d}\n", .{sample, @tagName(op), capture, @divTrunc(ns()-t,500)});}}}}
Branches
Latest commits
- c1b153c4Merge branch 'records-1124c' into mainJukebox
- d7b5e780|||PR Records 2026-11-24 (2): live day72, PR #19 merge, #10 newsmre
- 43b564dbMerge branch 'records-1124b' into mainJukebox
- fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
- 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
- 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
- 170d3735Merge branch 'code-order-2' into mainJukebox
- 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
- 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
- 0ba85799Merge branch 'reset-classes' into mainJukebox
- 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
- 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
- dcca21abjukebox#8 Move copies and queue logic into their topicsmre
- 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
- bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
- a3796dc5Records: live step waits for idlemre
- 3b158e16Records: merges of #9 and #11mre
- 27204167Merge main into records-1123mre
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox