perf(coderd/database/db2sdk): avoid constructing a full git provider per chat row
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Refactoring
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- go
- Ambito
- backend, performance
Direzione di ricerca
Leggi coderd/database/db2sdk/db2sdk.go, in particolare il convertitore dello stato del diff della chat e i suoi chiamanti Chat, ChildChatRows e ChatRowsWithChildren, quindi esamina la costruzione di gitprovider e i metodi URL. Confronta le due forme di correzione proposte, esegui i test e i benchmark pertinenti di chat/database se disponibili e conferma che la conversione non costruisce più un provider per riga, mentre gli URL del repository e del branch rimangono corretti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Follow-up from #27711 (CRF-16).
Problem
coderd/database/db2sdk/db2sdk.go constructs a full GitHub provider per converted chat row to run two pure string functions (ParseRepositoryOrigin and BuildBranchURL).
Measured by four independent reviewers in round 1 of #27711:
- Construction cost: ~46-73 us, ~46 KB, 451 allocations per call, dominated by three
regexp.MustCompilecalls innewGitHubplus a fresh 2048-slot cache map. - The two string functions actually needed cost ~1.1 us and 195 B. So 97% of the work is thrown away.
- The construction runs per row via
Chat,ChildChatRowsandChatRowsWithChildren(10 call sites), reached from the chat list endpoint. A 100-row list response with branch-but-no-PR rows pays roughly 5 to 7 ms and 4.6 MB of garbage.
Correctness is unaffected: this path only parses and formats URLs, so no ETag state is lost. The code in question:
// coderd/database/db2sdk/db2sdk.go, inside the chat diff status converter
// TODO: This uses the default github.com API base URL,
// so branch URLs for GitHub Enterprise instances will
// be incorrect.
gp, _ := gitprovider.New("github", "", nil)
if gp != nil {
if owner, repo, _, ok := gp.ParseRepositoryOrigin(status.GitRemoteOrigin); ok {
branchURL := gp.BuildBranchURL(owner, repo, status.GitBranch)
...
}
}
Two fix shapes
-
Cheap: package-level
sync.OnceValuefor the default github.com provider.- About 5 lines. Kills 97% of the waste for the github.com case, which is the only host this code ever targets today (
gitprovider.New("github", "", nil)hardcodes the default base URL). - Does not fix the GHE case, but that case is already broken today per the existing TODO.
- About 5 lines. Kills 97% of the waste for the github.com case, which is the only host this code ever targets today (
-
Proper: move URL parsing and building into package-level functions with package-level regexps, and have the provider methods delegate.
- About 40 lines, but touches the
Providerinterface (all implementations). - Removes the incentive to construct a provider for string work, not just the cost.
- Also fixes the existing TODO (GitHub Enterprise hosts get wrong branch URLs) if the functions take the host as a parameter.
- About 40 lines, but touches the
The existing TODO above the call already records the correctness half of the same design gap.
Context from #27711
This is the last live instance of the exact class that PR fixed one layer up: per-call provider construction throwing away work and state. Seven reviewers found it independently in round 1, all rated it P4, four with benchmarks that agreed. It predates #27711 and carries no cache state, which is why it stayed out of that PR.
🤖 Generated by Coder Agents on behalf of @johnstcn.
- Lingua principale
- Go
- Stelle
- 16.6k
- Fork
- 1.6k
- Merge medio
- 2g 4h
- PR unite (30g)
- 501
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di coder/coder
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
coder/coder#30047 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
coder/coder#29968 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
coder/coder#29962 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
coder/coder#29955 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexistApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
coder/coder#29623 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
agentic-workflows
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
priority/4/normal status/needs-triage type/bug/unconfirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
authelia/authelia#13292 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
blinklabs-io/actions#138 ·
I maintainer di solito rispondono entro 1 giorno
-
[UI] AlbumDetails collapses multi-genre list to single primary genre on viewports < lg breakpointAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno