Title: perf(coderd/database/db2sdk): avoid constructing a full git provider per chat row · Issue #28142 · coder/coder · GitHub
Open Graph Title: perf(coderd/database/db2sdk): avoid constructing a full git provider per chat row · Issue #28142 · coder/coder
X Title: perf(coderd/database/db2sdk): avoid constructing a full git provider per chat row · Issue #28142 · coder/coder
Description: 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 r...
Open Graph Description: 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 BuildBr...
X Description: 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 BuildBr...
Opengraph URL: https://github.com/coder/coder/issues/28142
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"perf(coderd/database/db2sdk): avoid constructing a full git provider per chat row","articleBody":"Follow-up from #27711 (CRF-16).\n\n## Problem\n\n`coderd/database/db2sdk/db2sdk.go` constructs a full GitHub provider per converted chat row to run two pure string functions (`ParseRepositoryOrigin` and `BuildBranchURL`).\n\nMeasured by four independent reviewers in round 1 of #27711:\n\n- Construction cost: **~46-73 us, ~46 KB, 451 allocations** per call, dominated by three `regexp.MustCompile` calls in `newGitHub` plus a fresh 2048-slot cache map.\n- The two string functions actually needed cost **~1.1 us and 195 B**. So **97% of the work is thrown away**.\n- The construction runs per row via `Chat`, `ChildChatRows` and `ChatRowsWithChildren` (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**.\n\nCorrectness is unaffected: this path only parses and formats URLs, so no ETag state is lost. The code in question:\n\n```go\n// coderd/database/db2sdk/db2sdk.go, inside the chat diff status converter\n// TODO: This uses the default github.com API base URL,\n// so branch URLs for GitHub Enterprise instances will\n// be incorrect.\ngp, _ := gitprovider.New(\"github\", \"\", nil)\nif gp != nil {\n\tif owner, repo, _, ok := gp.ParseRepositoryOrigin(status.GitRemoteOrigin); ok {\n\t\tbranchURL := gp.BuildBranchURL(owner, repo, status.GitBranch)\n\t\t...\n\t}\n}\n```\n\n## Two fix shapes\n\n1. **Cheap: package-level `sync.OnceValue`** for the default github.com provider.\n - 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).\n - Does not fix the GHE case, but that case is already broken today per the existing TODO.\n\n2. **Proper: move URL parsing and building into package-level functions** with package-level regexps, and have the provider methods delegate.\n - About 40 lines, but touches the `Provider` interface (all implementations).\n - Removes the incentive to construct a provider for string work, not just the cost.\n - Also fixes the existing TODO (GitHub Enterprise hosts get wrong branch URLs) if the functions take the host as a parameter.\n\nThe existing `TODO` above the call already records the correctness half of the same design gap.\n\n## Context from #27711\n\nThis 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.\n\n> 🤖 Generated by Coder Agents on behalf of @johnstcn.","author":{"url":"https://github.com/johnstcn","@type":"Person","name":"johnstcn"},"datePublished":"2026-08-13T17:37:01Z","url":"https://github.com/coder/coder/issues/28142"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:88a27a1a-7beb-db10-8b98-8245fb3d0a8d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B54A:32A711:620975:8707AB:6B04A4FC |
| html-safe-nonce | 2f2e1c903b51213bb5391be7f7dc980d0701acfa3bb9d4221da910f3acb92053 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTRBOjMyQTcxMTo2MjA5NzU6ODcwN0FCOjZCMDRBNEZDIiwidmlzaXRvcl9pZCI6IjM4NzgwMTA5OTIyMzE0OTA4MTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d08c1379e784c6de5a23060c4e656dd7d802e986289a67c6dd15e4a39cde935a |
| hovercard-subject-tag | issue:5144128986 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/coder/28142/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8d0ff37f150b089a6b1bcdad852c1768053857b968a1f8a5fdeee27370f119d1/coder/coder/issues/28142 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8d0ff37f150b089a6b1bcdad852c1768053857b968a1f8a5fdeee27370f119d1/coder/coder/issues/28142 |
| og:image:alt | 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 BuildBr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johnstcn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 188497a0f45a7aa8f7c866faa1950d1a7f8d82b59416adf549b222ad1d1dd19b |
| turbo-cache-control | no-preview |
| go-import | github.com/coder/coder git https://github.com/coder/coder.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 440752086 |
| octolytics-dimension-repository_nwo | coder/coder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 440752086 |
| octolytics-dimension-repository_network_root_nwo | coder/coder |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 557cfbac6cdb532730c95c90f2cefdc0c4128029 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width