Repository navigation
perf(providers): stop paying for the same provider detail twice - #23
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: trueque oRefreshintroduziu faziacaptureSnapshotir à rede de novo, jogando fora a resposta quefetchArtacabara de buscar. Duas requisições e duas fichas por obra, para o mesmo detalhe.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 novite devmede 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 ERRORnobetter-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