A window's cost grows with its rows (Q4: 8 rows ~20 ms, 16 ~34): in a run being copied (a code edit) the match is long and the drafts are kept, a short match (new code) is mostly a coincidence
| 377 | // A window's cost grows with its rows (Q4: 8 rows ~20 ms, 16 ~34): in a run being copied (a code edit) the match is long |
| 378 | // and the drafts are kept, a short match (new code) is mostly a coincidence |
| 379 | std::vector<int> lookup_drafts(const std::vector<int>& ctx, int lk, int d1) { |
| 380 | std::vector<int> r; |
| 381 | if (lk == 0 || (int) ctx.size() <= LOOKUP_N) return r; |
| 382 | const size_t n0 = ctx.size() - LOOKUP_N; |
| 383 | for (size_t s = n0; s-- > 0;) |
| 384 | if (std::equal(ctx.begin() + s, ctx.begin() + s + LOOKUP_N, ctx.begin() + n0)) { |
| 385 | if (s + LOOKUP_N < ctx.size() && (d1 < 0 || ctx[s + LOOKUP_N] == d1)) { |
| 386 | int m = LOOKUP_N; |
| 387 | while (m < lk && (size_t) (m - LOOKUP_N) < s && ctx[s - 1 - (m - LOOKUP_N)] == ctx[n0 - 1 - (m - LOOKUP_N)]) ++m; |
| 388 | const int k = std::min(lk, std::max(LOOKUP_MIN, m)); |
| 389 | r.assign(ctx.begin() + s + LOOKUP_N, ctx.begin() + std::min(ctx.size(), s + LOOKUP_N + k)); |
| 390 | } |
| 391 | break; |
| 392 | } |
| 393 | // an image cell is never a draft (nor anything after it) |
| 394 | r.erase(std::find_if(r.begin(), r.end(), [](int t) { return t >= Engine::IMAGE_TOK; }), r.end()); |
| 395 | return r; |
| 396 | } |
| 397 | |
| 398 | Finish Session::generate(int max_new, const Sampling& s, const std::function<void(int)>& emit, const std::atomic<bool>* stop, |
| 399 | GenStats& st) { |