From be297ead16b41938e84bcc3f1be628bc8725f2f4 Mon Sep 17 00:00:00 2001 From: eunhhu Date: Thu, 1 Oct 2026 05:34:25 +0100 Subject: Count work only under a budget, and say why a view failed only then (017) The work budget added about 26 instructions to every row of a table a host shows (bank, a table of 10,000 rows: +3.0% instructions an ask), which 017's one-app criterion allows at 1%. A sample put most of it in show_given asking every cell why it failed, and the rest in evaluate and the row lookup writing that reason and the count for every cell. Now nothing is counted without a budget (PureApp.work stays), the reason is written only when a view, a cell or a row has no value, and pure-serve asks it only of a cell without one. The table: +0.94%; the other bank queries within 0.4%. The tests that read the count set a budget that is never reached. --- serve/serve.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'serve') diff --git a/serve/serve.c b/serve/serve.c index 5ba137f..b7a122e 100644 --- a/serve/serve.c +++ b/serve/serve.c @@ -1425,28 +1425,27 @@ static PureResult show_given(PureApp *app, const Route *route, size_t available, for (unsigned k = 0; k < count; ++k) { put_bytes(&o, columns[k].key + !k, columns[k].length - !k); uint8_t kind = m->view_type[columns[k].view]; + bool valued; if (kind == PURE_VIEW_I64) { int64_t integer; - if (!pure_app_cell_i64(app, columns[k].view, row, &integer)) put_bytes(&o, "null", 4); - else put_integer(&o, integer); + if ((valued = pure_app_cell_i64(app, columns[k].view, row, &integer))) put_integer(&o, integer); } else if (kind == PURE_VIEW_NUM || kind == PURE_VIEW_BOOL) { - if (!pure_app_cell(app, columns[k].view, row, &value)) put_bytes(&o, "null", 4); - else if (kind == PURE_VIEW_BOOL) put_bytes(&o, value ? "true" : "false", value ? 4 : 5); + if (!(valued = pure_app_cell(app, columns[k].view, row, &value))) { + } else if (kind == PURE_VIEW_BOOL) put_bytes(&o, value ? "true" : "false", value ? 4 : 5); else put_number(&o, value); } else { size_t mark = o.size; put_bytes(&o, "\"", 1); - if (pure_app_cell_text(app, columns[k].view, row, put_json_span, &o) == PURE_OK) put_bytes(&o, "\"", 1); - else if (!o.failed) { - o.size = mark; - put_bytes(&o, "null", 4); - } + if ((valued = pure_app_cell_text(app, columns[k].view, row, put_json_span, &o) == PURE_OK)) put_bytes(&o, "\"", 1); + else o.size = o.failed ? o.size : mark; } + if (valued) continue; if (pure_app_view_fault(app) == PURE_FAULT_WORK) { /* a cell past the work budget fails the table */ status = PURE_LIMIT; end = row; break; } + put_bytes(&o, "null", 4); /* a cell without a value */ } put_bytes(&o, "}", 1); } -- cgit v1.2.3