diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Names.zig | 20 | ||||
| -rw-r--r-- | core/Places.zig | 21 | ||||
| -rw-r--r-- | core/replica.zig | 3 | ||||
| -rw-r--r-- | core/tape.zig | 15 |
4 files changed, 21 insertions, 38 deletions
diff --git a/core/Names.zig b/core/Names.zig index fff2c84f..2fbbec37 100644 --- a/core/Names.zig +++ b/core/Names.zig @@ -2,7 +2,7 @@ //! directory (listed by the disk engine, Stream.zig), the recent files, the open panes, //! a file's declarations. Each keystroke scores them again with a small //! fzf-style scorer (subsequence, Smith-Waterman with affine gaps, bonuses -//! at the starts of words and path segments), a frame's budget at a time, +//! at the starts of words and path segments), a frame's count at a time, //! the best kept first. Lifted from the pick prototype (Pick.zig), whose //! scorer took ~1 ms for 20k paths in a release build. Embedded in a //! Query; the rows it shows are the Query's to make. @@ -56,8 +56,12 @@ pub const max_query = 64; /// A candidate is scored over its first this many bytes. const max_text = 512; const max_cands = 200_000; -/// A keystroke's scoring, and a frame's: what is left waits a frame. -const score_budget_ns = 4 * std.time.ns_per_ms; +/// A keystroke's scoring, and a frame's: at most this many of the +/// scorer's cells (a key's bytes times the query's and one: what `match` +/// can visit of a candidate); what is left waits a frame. A count, not the +/// clock: a client's guess of a key scores as far as the session's step +/// (P27, P30). About 4 ms in a release build (`pardes-perf --search`). +const score_cells = 3_000_000; pub fn deinit(n: *Names, gpa: std.mem.Allocator) void { n.bytes.deinit(gpa); @@ -136,12 +140,12 @@ pub fn typed(n: *Names, gpa: std.mem.Allocator, text: []const u8) void { } /// Scores the pending candidates, then `cands[scored..]`, into `hits`, and -/// sorts them: at most `score_budget_ns` of it a call, the rest on the -/// next frames while the best so far is shown. +/// sorts them: at most `score_cells` of it a call, the rest on the next +/// frames while the best so far is shown. pub fn rescore(n: *Names, gpa: std.mem.Allocator) void { const q = n.queryText(); const empty = std.mem.trim(u8, q, " ").len == 0; - const started = pardes.FrameStats.nowNs(); + var left: usize = score_cells; const had = n.hits.items.len; const was_scored = n.scored; var count: usize = 0; @@ -157,8 +161,8 @@ pub fn rescore(n: *Names, gpa: std.mem.Allocator) void { const key = n.bytes.items[c.start + c.key ..][0..c.key_len]; const s = if (empty) 0 else match(q, key, n.lower.items[c.start + c.key ..][0..c.key_len], c.base, null, null); if (s) |score| n.hits.append(gpa, .{ .cand = i, .score = score }) catch break; - // The clock every 256 candidates: reading it is not free either. - if (!empty and count % 256 == 255 and pardes.tape.over(started, score_budget_ns)) break; + left -|= @as(usize, @min(c.key_len, max_text)) * (q.len + 1); + if (!empty and left == 0) break; } // An empty query keeps the source's order (the walk's, recency): no // row moves as the walk goes on, it only grows at the foot. diff --git a/core/Places.zig b/core/Places.zig index 9ffbff88..35b79805 100644 --- a/core/Places.zig +++ b/core/Places.zig @@ -46,13 +46,14 @@ pub const Provenance = enum { typed, search, list }; /// Places past this many are not kept. ponytail: 16 bytes a place, 16 MB /// at the cap; a sparse count past it if a million is ever too few. pub const max_hits = 1 << 20; -/// What one frame spends finding places: about 4 ms on the clock, checked -/// between pieces of the text; mvzr's steps (Regex.budget is about 300 ms -/// of them, so this is about 5 ms), which bound one slow piece; and bytes -/// read, the bound where there is no clock. -pub const frame_ns: u64 = 4 * std.time.ns_per_ms; +/// What one frame spends finding places: bytes of the text read (and the +/// places an insert above the view moves, as many bytes), about 4 ms in a +/// release build (`pardes-perf --search`); and mvzr's steps (Regex.budget +/// is about 300 ms of them, so this is about 5 ms), which bound one slow +/// piece. Counts, not the clock: a replica finds as many places a frame as +/// its session (P27, P30). pub const frame_steps: u64 = regexp.Regex.budget / 64; -pub const frame_bytes: usize = 8 << 20; +pub const frame_bytes: usize = 512 << 10; /// The text is searched in pieces of about this much, each ending at a /// line's end, so that a budget runs out between pieces, not inside one. /// A folding set lowers its copy of the text a piece at a time too. @@ -405,7 +406,6 @@ fn restart(set: *Places, p: *Pardes, f: *File.State) void { /// been searched, make it current. Run after every step (with no budget: /// the view only) and every tick (a frame's). pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) void { - const started_ns = pardes.FrameStats.nowNs(); if (!set.started) return; set.derive(p.gpa); const f = if (pane.file) |*file| file else return set.clear(p.gpa); @@ -490,17 +490,14 @@ pub fn fill(set: *Places, p: *Pardes, pane: *Pane, bytes: usize, steps: u64) voi } if (forward) set.hi = at else { set.hits.insertSlice(gpa, set.nhead, head.items) catch return; + // With many places below, moving them is most of the work. + left -|= (set.hits.items.len - set.nhead - head.items.len) * @sizeOf(Hit); if (set.current) |*c| c.* += head.items.len; set.nhead += head.items.len; set.head_to = at; } left -|= at - from; if (short) break; - // A frame's time spent (a whole search's for n and N, whose steps - // are mvzr's whole budget). - // The clock's verdict is the session's (core/tape.zig): a replica - // finds as many places a frame as this did. - if (started_ns != 0 and bytes != std.math.maxInt(usize) and pardes.tape.over(started_ns, frame_ns)) break; } if (set.hits.items.len != found_before) { set.gen +%= 1; diff --git a/core/replica.zig b/core/replica.zig index 67a29df3..31e16f46 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -6604,9 +6604,6 @@ test "a client joined from a dump lands a click on a rail's tick as the session r.confirm(try a.take(m)); r.settle(); } - // (The key may be mispredicted: a step's places are a frame's time's - // worth, `tape.over`, the session's verdict, and its drawn caches let - // it find more in that time than the client's speculation did.) try agrees(a, r); try std.testing.expectEqual(a.core.panes[owner].?.places.current, r.core().panes[owner].?.places.current); } diff --git a/core/tape.zig b/core/tape.zig index f9303d67..934bc499 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -114,7 +114,6 @@ pub const Site = enum(u16) { fonts, // Read in place (`value`). clock, - budget, wake, env, interpreter, @@ -768,12 +767,6 @@ pub const Tape = struct { return t.value(.authority, f, args); } - /// A budget of `budget_ns` from `since_ns` on the monotonic clock is spent: - /// what the clock said is taped, so a replica stops its work where this did. - pub fn over(t: *Tape, since_ns: u64, budget_ns: u64) bool { - return t.value(.budget, overNow, .{ since_ns, budget_ns }); - } - /// A body whose first parameter is an `std.Io` its caller does not pass /// is handed the tape's (`args` are the rest): the only way core/ comes /// to hold one. @@ -1324,14 +1317,6 @@ pub fn resync(t: *Tape) void { t.real = .{}; } -pub fn over(since_ns: u64, budget_ns: u64) bool { - return (on orelse &none).over(since_ns, budget_ns); -} - -fn overNow(since_ns: u64, budget_ns: u64) bool { - return pardes.FrameStats.nowNs() -| since_ns > budget_ns; -} - /// One host call, `f(args)`, made out of the turn (pardes.turn). pub fn out(comptime f: anytype, args: anytype) @typeInfo(@TypeOf(f)).@"fn".return_type.? { pardes.turn.yield(); |
