Skip to content

perf(providers): stop paying for the same provider detail twice - #23

Merged
Digit4w merged 2 commits into
devfrom
perf/warm-throughput
Sep 14, 2026
Merged

Digit4w merged 2 commits into
devfrom
perf/warm-throughput

Conversation

@Digit4w

@Digit4w Digit4w commented Sep 14, 2026

Copy link
Copy Markdown
Owner

O dono testou as features do ciclo anterior e reportou dois problemas. Este PR é o lado do servidor.

O achado, e ele não era o que eu procurava. Fui atrás de "o aquecimento está lento" supondo que o colchão do limitador fosse a causa. Não era: o fresh: true que o Refresh introduziu fazia captureSnapshot ir à rede de novo, jogando fora a resposta que fetchArt acabara de buscar. Duas requisições e duas fichas por obra, para o mesmo detalhe.

antes depois
Varredura 0,47 obras/s 1,84 obras/s
1.442 obras ~51 min ~13 min
Requisições ao provedor 2 por obra 1

O colchão caiu de metade do burst para um quinto, e o número saiu de medir o custo dele. Metade foi calibrada contra o AniList (0,5/s), onde a disputa machuca de verdade; num provedor a 3/s ela cobrava caro e protegia pouco — medido, uma grade fria leva o mesmo tempo com o aquecimento rodando (2,97s) e sem ele (2,78s). Proteger a tela devagar demais é deixá-la desprotegida por mais tempo.

E o trabalho de fundo voltou a debitar a ficha. A primeira versão o fazia dormir sem debitar e tentar de novo, para que uma fila de mil obras não passasse à frente de quem abriu a grade — mas o aquecimento é um laço sequencial, que só pede a ficha seguinte depois de terminar a obra anterior. Nunca houve fila a evitar; o que o retry produzia era espera repetida. Com o laço removido, não debitar teria deixado o fundo sem teto nenhum — e o teste que afirma isso passou verde na primeira versão porque não distinguia as duas implementações, o que foi refeito.

Junto vem bun run preview, que builda o cliente e sobe o servidor servindo aquele build. Ele existe porque medir performance no vite dev mede a coisa errada, e isso custou um ciclo inteiro: o mesmo gesto leva 120–140ms de interface parada lá e nenhuma tarefa longa contra o build de produção. Bun no lugar do Node não resolve — no servidor ele nem roda (panic: NAPI FATAL ERROR no better-sqlite3), o que é uma segunda razão para a decisão de runtime que o brief já tinha tomado.

Contraparte: Digit4w/watchpile-client#30. Mergear este primeiro.

Testes: 811.

🤖 Generated with Claude Code

The library sweep ran at 0.47 titles/s against a 3/s ceiling, and each
title cost 2.1s — while the provider detail measures 0.37s and the image
another 0.37s. The gap was a second round trip nobody needed.

fetchArt and captureSnapshot read the SAME detail, and the first one had
just filled provider_cache with it. Passing fresh to both threw that
away: two requests and two limiter tokens per title. fresh now applies
only when the art was not fetched in this pass, which is the case where
there is no first response to reuse.

The background cushion drops from half the burst to a fifth, and that
number came from measuring its cost rather than from taste. Half was
calibrated against AniList at 0.5/s, where contention genuinely hurts.
On a 3/s provider it was charging a lot and protecting little: a cold
grid took the same time with warming running (2.97s) and without it
(2.78s). Protecting the screen too slowly leaves it unprotected for
longer.

Background work also debits its token again. The first version had it
sleep without debiting and retry, so that a queue of a thousand titles
would not cut ahead of someone opening the grid — but warming is a
SEQUENTIAL loop that asks for the next token only after finishing the
previous title, so there was never a queue to avoid. What the retry
produced was repeated waiting. With the loop gone, not debiting would
have left background work with no ceiling at all.

Measured after: 0.47 -> 1.84 titles/s, and half the provider requests.
Measuring performance in `vite dev` measures the wrong thing, and that
cost a full diagnosis cycle: returning from a title to /library took
120-140ms of frozen UI there and no long task at all against the
production build, on the same gesture with 1442 titles.

The gap is not Vite. It is React in development mode, which mounts every
component twice under StrictMode (a no-op in production) and ships
unminified. No bundler or runtime swap moves it — bun in place of node
starts the dev server ~0.3s sooner and changes nothing after, and on the
server it does not run at all: better-sqlite3 panics with a NAPI fatal
error, which is a second reason for the runtime decision the brief
already made.

It builds the client and serves that build, in one command. It is not
real production — the server still runs through tsx rather than dist/ —
and that is deliberate: what this exists to observe is the screen, and
the API answers in milliseconds either way. Packaging for real stays
electron:build or the Docker image.

It does not go in the README. That file is for people installing
Watchpile; this is scaffolding for people writing it.
@Digit4w
Digit4w merged commit ab842f6 into dev Sep 14, 2026
2 checks passed
@Digit4w
Digit4w deleted the perf/warm-throughput branch September 14, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant