summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 22:53:14 -0300
committerGabriel Schneider <[email protected]>2026-11-04 22:53:58 -0300
commit57a72221f8db2d54421a67819a7fcca2debf8157 (patch)
tree4599906749a525953a18b2d3bb454f4ce220cce6 /src
parent0f46b51232650f2962cd57cded49a4ca8493bc65 (diff)
downloadpardes-57a72221f8db2d54421a67819a7fcca2debf8157.tar.gz
pardes-57a72221f8db2d54421a67819a7fcca2debf8157.zip
Stream: the counters and clocks nothing read go (hits, files, scanned, started_ns, first_ns, finished_ns, worker_ns, the batch's and the worker's copies, rg's summary parse), and PARDES_STREAM_ENGINE, which nothing set: the tests force the engine through the field
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/Stream.zig66
1 files changed, 8 insertions, 58 deletions
diff --git a/src/Stream.zig b/src/Stream.zig
index d065e055..8e51b797 100644
--- a/src/Stream.zig
+++ b/src/Stream.zig
@@ -51,18 +51,13 @@ const max_file_bytes = 16 << 20;
pub const Batch = struct {
gen: u32,
rows: []u8 = &.{},
- hits: u32 = 0,
- /// Files with a hit in this batch's rows.
- files: u32 = 0,
- /// Files read since the last batch (rg: all of them, at its end).
- scanned: u32 = 0,
/// Directories it might not open.
skipped: u32 = 0,
engine: Engine = .walk,
/// The worker waits at its soft cap until More.
capped: bool = false,
end: ?End = null,
- /// The worker's own time, start to end (in the last batch).
+ /// A parse's own time on the worker (`parse_ns`).
took_ns: u64 = 0,
/// A parse's answer (`parseFor`): the declarations of pane `serial`'s
/// text at `revision`.
@@ -165,7 +160,7 @@ pub const Job = struct {
/// Rows name files relative to this, the query pane's directory, which
/// is also the one root searched.
base: []u8,
- /// Forced (tests, PARDES_STREAM_ENGINE); else rg when there is one.
+ /// Forced (tests); else rg when there is one.
engine: ?Engine,
/// Hits it may send before it waits; More raises it and wakes it. Run
/// on the loop (no worker) it is a hard stop.
@@ -189,9 +184,9 @@ pub const replica = .{
// The worker a search runs on, which the host starts.
.authority = .{"task"},
.local = .{
- "started_ns", "first_ns", "finished_ns", "worker_ns", "parse_ns",
- "paint", "paint_retired", "paint_count", "ahead", "ahead_for",
- "painted_ahead", "painted_on_loop", "ahead_seen", "ahead_ask",
+ "parse_ns", "paint", "paint_retired", "paint_count",
+ "ahead", "ahead_for", "painted_ahead", "painted_on_loop",
+ "ahead_seen", "ahead_ask",
},
};
@@ -208,16 +203,9 @@ task: ?Task = null,
/// Forced engine (tests); null, rg when it runs.
engine: ?Engine = null,
used: Engine = .walk,
-hits: u32 = 0,
-files: u32 = 0,
-scanned: u32 = 0,
skipped: u32 = 0,
/// Stale batches dropped (the race test counts them).
dropped: usize = 0,
-started_ns: u64 = 0,
-first_ns: ?u64 = null,
-finished_ns: u64 = 0,
-worker_ns: u64 = 0,
/// The parse running or about to (one at a time), its generation, and the
/// one asked for while it ran (pane serial and revision), started after it.
parse: ?TextTask = null,
@@ -511,11 +499,7 @@ pub fn query(p: *Pardes, target: u32, kind: Kind, pattern: []const u8, dir: []co
s.pattern.appendSlice(p.gpa, pattern) catch return;
s.dir.clearRetainingCapacity();
s.dir.appendSlice(p.gpa, dir) catch return;
- s.hits = 0;
- s.files = 0;
- s.scanned = 0;
s.skipped = 0;
- s.first_ns = null;
s.state = .waiting;
s.due_ns = if (how == .typed) p.now_ns + debounce_ns else p.now_ns;
if (kind == .grep) s.rows_asked = @splat(0);
@@ -528,7 +512,6 @@ pub fn stop(s: *Stream) bool {
s.due_ns = null;
s.gen +%= 1;
s.state = .stopped;
- s.finished_ns = now();
return true;
}
@@ -567,7 +550,6 @@ pub fn step(p: *Pardes) void {
if (p.now_ns < due) return;
s.due_ns = null;
s.state = .searching;
- s.started_ns = now();
// A script's write (whose answer says whether it found anything) and a
// host with no workers: done before this returns.
if (p.host.vtable.search != null and !p.fs.serving) p.emit(.{ .search = .{ .gen = s.gen } }) else runHere(p, s.gen);
@@ -708,16 +690,10 @@ pub fn receive(p: *Pardes, b: *const Batch) void {
return;
}
s.used = b.engine;
- s.hits += b.hits;
- s.files += b.files;
- s.scanned += b.scanned;
s.skipped += b.skipped;
- if (s.first_ns == null and b.rows.len > 0) s.first_ns = now();
if (b.capped) s.state = .capped;
if (b.end) |end| {
- s.worker_ns = b.took_ns;
s.state = if (end == .failed) .failed else .done;
- s.finished_ns = now();
// It sent its last: its join is a return away.
if (s.task) |t| {
s.task = null;
@@ -770,14 +746,10 @@ const Worker = struct {
engine: Engine = .walk,
exact: bool,
rows: std.ArrayList(u8) = .empty,
- hits: u32 = 0,
- files: u32 = 0,
- scanned: u32 = 0,
skipped: u32 = 0,
total: u32 = 0,
sent: bool = false,
batch_began: ?std.Io.Timestamp = null,
- began: std.Io.Timestamp,
/// One read buffer for every file: grown to the biggest, never 0xAA'd per file.
buf: std.ArrayList(u8) = .empty,
@@ -791,18 +763,11 @@ const Worker = struct {
const batch: Batch = .{
.gen = w.job.gen,
.rows = rows,
- .hits = w.hits,
- .files = w.files,
- .scanned = w.scanned,
.skipped = w.skipped,
.engine = w.engine,
.capped = capped,
.end = end,
- .took_ns = if (end != null) @intCast(@max(0, w.began.durationTo(std.Io.Clock.awake.now(w.io)).nanoseconds)) else 0,
};
- w.hits = 0;
- w.files = 0;
- w.scanned = 0;
w.skipped = 0;
w.sent = true;
w.batch_began = null;
@@ -860,16 +825,13 @@ const Worker = struct {
var cut = @min(ln.len, 400);
while (cut > 0 and cut < ln.len and ln[cut] & 0xc0 == 0x80) cut -= 1;
try w.rows.print(w.gpa, "{s}:{d}:{d}{c}{d} {s}\n", .{ path, line, from + 1, config.range_sep, end, ln[0..cut] });
- w.hits += 1;
w.total += 1;
}
/// A listing's file: its name, relative to the base.
fn file(w: *Worker, path: []const u8) !bool {
try w.rows.print(w.gpa, "{s}\n", .{path});
- w.hits += 1;
w.total += 1;
- w.files += 1;
try w.maybeSend();
return w.checkCap();
}
@@ -964,11 +926,9 @@ const Worker = struct {
else => return false,
};
const text = w.buf.items[0..n];
- w.scanned += 1;
if (std.mem.indexOfScalar(u8, text[0..@min(text.len, 1024)], 0) != null) return false;
const found = try w.grepText(path, text);
if (found == 0) return false;
- w.files += 1;
try w.maybeSend();
return w.checkCap();
}
@@ -1030,7 +990,6 @@ const Worker = struct {
// a dot-file is passed over, as the walk passes over
// dot-directories
if (std.mem.startsWith(u8, std.fs.path.basename(line.items), ".")) continue;
- w.scanned += 1;
if (try w.file(w.shown(line.items))) {
cut = true;
break :read;
@@ -1068,7 +1027,6 @@ const Worker = struct {
file_hits += 1;
} else if (std.mem.eql(u8, kind.string, "end")) {
if (file_hits == 0) continue;
- w.files += 1;
file_hits = 0;
try w.maybeSend();
// At the cap rg is left blocked on its full pipe: its
@@ -1077,10 +1035,6 @@ const Worker = struct {
cut = true;
break :read;
}
- } else if (std.mem.eql(u8, kind.string, "summary")) {
- if (data.get("stats")) |stats| if (stats == .object) if (stats.object.get("searches")) |v| if (v == .integer) {
- w.scanned = @intCast(v.integer);
- };
}
}
try line.appendSlice(w.gpa, chunk[at..n]);
@@ -1104,13 +1058,9 @@ fn jsonText(v: ?std.json.Value) ?[]const u8 {
fn work(io: std.Io, job: *Job, ctx: ?*anyopaque, sink: Sink) void {
var exact = false;
for (job.pattern) |c| exact = exact or std.ascii.isUpper(c);
- var w: Worker = .{ .io = io, .gpa = job.gpa, .job = job, .ctx = ctx, .sink = sink, .exact = exact, .began = std.Io.Clock.awake.now(io) };
+ var w: Worker = .{ .io = io, .gpa = job.gpa, .job = job, .ctx = ctx, .sink = sink, .exact = exact };
defer w.deinit();
- const forced: ?Engine = job.engine orelse if (std.c.getenv("PARDES_STREAM_ENGINE")) |v|
- std.meta.stringToEnum(Engine, std.mem.span(v))
- else
- null;
- const ran = if ((forced orelse .rg) == .rg) w.ripgrep() else error.NoRipgrep;
+ const ran = if ((job.engine orelse .rg) == .rg) w.ripgrep() else error.NoRipgrep;
ran catch |err| switch (err) {
error.Canceled, error.Refused => return,
error.NoRipgrep => {
@@ -1202,7 +1152,7 @@ const Rogue = struct {
defer r.done.store(true, .release);
while (!r.stop.load(.acquire) and r.pushed < 200) {
const rows = testing.allocator.dupe(u8, "d00/f000.txt:1:3-8 stale stale\n") catch return;
- if (!host_io.Inbox.pushSearch(r.q, .{ .gen = r.gen, .rows = rows, .hits = 1, .files = 1 })) return;
+ if (!host_io.Inbox.pushSearch(r.q, .{ .gen = r.gen, .rows = rows })) return;
r.pushed += 1;
std.Thread.yield() catch {};
}