summaryrefslogtreecommitdiff
path: root/core/Names.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Names.zig')
-rw-r--r--core/Names.zig20
1 files changed, 12 insertions, 8 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.