René's URL Explorer Experiment


Title: perf: reuse OpenAI client and add undici keep-alive Agent with connection warmup by Lellansin · Pull Request #100 · lessweb/deepcode-cli · GitHub

Open Graph Title: perf: reuse OpenAI client and add undici keep-alive Agent with connection warmup by Lellansin · Pull Request #100 · lessweb/deepcode-cli

X Title: perf: reuse OpenAI client and add undici keep-alive Agent with connection warmup by Lellansin · Pull Request #100 · lessweb/deepcode-cli

Description: 概述 优化 OpenAI API 客户端的 HTTP 连接复用,减少用户输入间隙的 TLS 握手开销。 背景 默认 undici 全局 fetch 的 TCP 连接保活时间仅 4 秒 CLI 场景下用户阅读 LLM 输出通常需要 10–30 秒,远超 4 秒阈值 每次新 prompt(含 chat、tool use)都需要重新完成 TCP+TLS 握手(实测 ~127ms),冷启动首字节延迟 200ms+ 性能收益 每次 LLM 调用(chat、tool use 等)减少 80ms~100ms,冷启动首字节延迟从约 210ms 降至约 130ms,降幅约 38%~43%。 指标 优化前 优化后 改善 TCP+TLS 握手 每次请求 仅首次预热一次 — 冷启动 TTFB ~210ms ~130ms ↓ 38% 连接保活 4s(默认) 180s 45x 首次请求 用户等待 启动时后台预热 用户无感知 数据来源:scripts/benchmark-optimization.mjs,API 为 api.deepseek.com,deepseek-chat 模型,3 轮连续对话。 可以参考 LOL、王者等游戏的 200+ms 延迟降低到 130ms,体感上这种延迟降低可以改善使用上的手感。 从绝对值来说,100 次 chat/tool_use 大概可以节约 10s,这对长任务来说也有一定的改善收益。 改动 用自定义 undici Agent(keepAliveTimeout: 180s)替换默认 fetch 缓存复用 OpenAI client 实例(按 apiKey + baseURL 匹配) 连接预热:App 挂载时 fire-and-forget 预建 TCP+TLS 连接(3s 超时保护) 将以上逻辑提取到 src/common/openai-client.ts,保持 App.tsx 精简 文件变更 文件 说明 package.json 新增 undici: ^7.25.0 src/common/openai-client.ts 新文件:undici Agent、client 缓存、连接预热、getMachineId src/ui/App.tsx 移除 ~90 行代码,改为从 common 模块引用 src/ui/index.ts 更新 re-export 路径 检查 ✅ TypeScript 类型检查 ✅ ESLint ✅ Prettier 格式 ✅ 311 项测试全部通过

Open Graph Description: 概述 优化 OpenAI API 客户端的 HTTP 连接复用,减少用户输入间隙的 TLS 握手开销。 背景 默认 undici 全局 fetch 的 TCP 连接保活时间仅 4 秒 CLI 场景下用户阅读 LLM 输出通常需要 10–30 秒,远超 4 秒阈值 每次新 prompt(含 chat、tool use)都需要重新完成 TCP+TLS 握手(实测 ~127ms),冷启动首字节延...

X Description: 概述 优化 OpenAI API 客户端的 HTTP 连接复用,减少用户输入间隙的 TLS 握手开销。 背景 默认 undici 全局 fetch 的 TCP 连接保活时间仅 4 秒 CLI 场景下用户阅读 LLM 输出通常需要 10–30 秒,远超 4 秒阈值 每次新 prompt(含 chat、tool use)都需要重新完成 TCP+TLS 握手(实测 ~127ms),冷启动首字节延...

Opengraph URL: https://github.com/lessweb/deepcode-cli/pull/100

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:b0ddc830-9bca-3add-64d2-19d541d6c292
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idEE30:3BF7C9:1B0CA6:2471FC:6A4D3298
html-safe-nonce1fc26775e99dab0b2c9de6b3be9860bb2fd38e6dfb7e71bfacfcedc1bb4b44c6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRTMwOjNCRjdDOToxQjBDQTY6MjQ3MUZDOjZBNEQzMjk4IiwidmlzaXRvcl9pZCI6Ijg4MDg1NTMwNTQ4Mjk2MjE5MTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac13446200c4cc4ac1bf54312c1a4907ed5c9df2392c382b43161ea7ec8bb5fe9a
hovercard-subject-tagpull_request:3716110063
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/lessweb/deepcode-cli/pull/100/files
twitter:imagehttps://avatars.githubusercontent.com/u/2081487?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/2081487?s=400&v=4
og:image:alt概述 优化 OpenAI API 客户端的 HTTP 连接复用,减少用户输入间隙的 TLS 握手开销。 背景 默认 undici 全局 fetch 的 TCP 连接保活时间仅 4 秒 CLI 场景下用户阅读 LLM 输出通常需要 10–30 秒,远超 4 秒阈值 每次新 prompt(含 chat、tool use)都需要重新完成 TCP+TLS 握手(实测 ~127ms),冷启动首字节延...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/lessweb/deepcode-cli git https://github.com/lessweb/deepcode-cli.git
octolytics-dimension-user_id118287711
octolytics-dimension-user_loginlessweb
octolytics-dimension-repository_id1223512305
octolytics-dimension-repository_nwolessweb/deepcode-cli
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1223512305
octolytics-dimension-repository_network_root_nwolessweb/deepcode-cli
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release56fc8347865a14e2ec811533d68f929cf4e0ec19
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/lessweb/deepcode-cli/pull/100/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Flessweb%2Fdeepcode-cli%2Fpull%2F100%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Flessweb%2Fdeepcode-cli%2Fpull%2F100%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=lessweb%2Fdeepcode-cli
Reloadhttps://github.com/lessweb/deepcode-cli/pull/100/files
Reloadhttps://github.com/lessweb/deepcode-cli/pull/100/files
Reloadhttps://github.com/lessweb/deepcode-cli/pull/100/files
Please reload this pagehttps://github.com/lessweb/deepcode-cli/pull/100/files
lessweb https://github.com/lessweb
deepcode-clihttps://github.com/lessweb/deepcode-cli
Notifications https://github.com/login?return_to=%2Flessweb%2Fdeepcode-cli
Fork 150 https://github.com/login?return_to=%2Flessweb%2Fdeepcode-cli
Star 1.7k https://github.com/login?return_to=%2Flessweb%2Fdeepcode-cli
Code https://github.com/lessweb/deepcode-cli
Issues 43 https://github.com/lessweb/deepcode-cli/issues
Pull requests 22 https://github.com/lessweb/deepcode-cli/pulls
Actions https://github.com/lessweb/deepcode-cli/actions
Projects https://github.com/lessweb/deepcode-cli/projects
Security and quality 0 https://github.com/lessweb/deepcode-cli/security
Insights https://github.com/lessweb/deepcode-cli/pulse
Code https://github.com/lessweb/deepcode-cli
Issues https://github.com/lessweb/deepcode-cli/issues
Pull requests https://github.com/lessweb/deepcode-cli/pulls
Actions https://github.com/lessweb/deepcode-cli/actions
Projects https://github.com/lessweb/deepcode-cli/projects
Security and quality https://github.com/lessweb/deepcode-cli/security
Insights https://github.com/lessweb/deepcode-cli/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Flessweb%2Fdeepcode-cli%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Flessweb%2Fdeepcode-cli%2Fissues%2Fnew%2Fchoose
qorzjhttps://github.com/qorzj
lessweb:mainhttps://github.com/lessweb/deepcode-cli/tree/main
Lellansin:dev/optimize-keepalive-client-reusehttps://github.com/Lellansin/deepcode-cli/tree/dev/optimize-keepalive-client-reuse
Conversation 0 https://github.com/lessweb/deepcode-cli/pull/100
Commits 9 https://github.com/lessweb/deepcode-cli/pull/100/commits
Checks 9 https://github.com/lessweb/deepcode-cli/pull/100/checks
Files changed https://github.com/lessweb/deepcode-cli/pull/100/files
Please reload this pagehttps://github.com/lessweb/deepcode-cli/pull/100/files
perf: reuse OpenAI client and add undici keep-alive Agent with connection warmup https://github.com/lessweb/deepcode-cli/pull/100/files#top
Show all changes 9 commits https://github.com/lessweb/deepcode-cli/pull/100/files
1bd7e6a perf: reuse OpenAI client instance and add connection warmup Lellansin May 19, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/1bd7e6a38c3f0f58a9b6971ba31d8c888d9f975d
2e5b2ed perf: replace undici fetch with custom https.Agent for long keepAlive Lellansin May 19, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/2e5b2ed2a4eed8c463546385ecbf374002a8d6c6
6f8d2e2 refactor: replace custom fetch wrapper with undici Agent Lellansin May 19, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/6f8d2e228d853f8014741c8108f6936e7d037c82
255226a chore: add undici devDependency for custom keepAlive Agent Lellansin May 19, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/255226a3c9bdd7254dd8b5728a0e1bff7de28707
5b74c00 fix: move undici from devDependencies to dependencies Lellansin May 19, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/5b74c00db5bf16e1519c6aaafb233c4c2b78bf1a
db78e2b fix: downgrade undici to v7 for Node 20 compatibility Lellansin May 19, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/db78e2b1756e2e9e2f9eea008e30e2f4638e0856
87d52ad fix: add 3s timeout to warmup request to prevent exit hang Lellansin May 19, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/87d52ade53833a18118e23a595f511a4823b0a6c
b2544b8 perf: reuse OpenAI client and add undici keep-alive Agent with connec… Lellansin May 20, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/b2544b831252c5d58f15cbfa6b5c7c04e1a1aa8f
61dbcc8 perf: extend keepAlive timeout from 60s to 180s Lellansin May 20, 2026 https://github.com/lessweb/deepcode-cli/pull/100/commits/61dbcc897b1ce8f93a7bf68d60092429c4b00bff
Clear filters https://github.com/lessweb/deepcode-cli/pull/100/files
Please reload this pagehttps://github.com/lessweb/deepcode-cli/pull/100/files
Please reload this pagehttps://github.com/lessweb/deepcode-cli/pull/100/files
package-lock.json https://github.com/lessweb/deepcode-cli/pull/100/files#diff-053150b640a7ce75eff69d1a22cae7f0f94ad64ce9a855db544dda0929316519
package.json https://github.com/lessweb/deepcode-cli/pull/100/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
openai-client.ts https://github.com/lessweb/deepcode-cli/pull/100/files#diff-9fb891054e0f90462fa3185f5d3af16d5e5ecf080d562154ae58819775dcf64c
App.tsx https://github.com/lessweb/deepcode-cli/pull/100/files#diff-0022b32944774e72bcbec1b0520e753925073bfbeff256269d0f668f5f515b0e
index.ts https://github.com/lessweb/deepcode-cli/pull/100/files#diff-8b9f572e7b966526733261e0898fc2731a8757c4427d099194655c1390aef48e
package-lock.jsonhttps://github.com/lessweb/deepcode-cli/pull/100/files#diff-053150b640a7ce75eff69d1a22cae7f0f94ad64ce9a855db544dda0929316519
View file https://github.com/Lellansin/deepcode-cli/blob/61dbcc897b1ce8f93a7bf68d60092429c4b00bff/package-lock.json
Open in desktop https://desktop.github.com
how customized files appear on GitHubhttps://docs.github.com/github/administering-a-repository/customizing-how-changed-files-appear-on-github
Please reload this pagehttps://github.com/lessweb/deepcode-cli/pull/100/files
package.jsonhttps://github.com/lessweb/deepcode-cli/pull/100/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
View file https://github.com/Lellansin/deepcode-cli/blob/61dbcc897b1ce8f93a7bf68d60092429c4b00bff/package.json
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/lessweb/deepcode-cli/pull/100/{{ revealButtonHref }}
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519
src/common/openai-client.tshttps://github.com/lessweb/deepcode-cli/pull/100/files#diff-9fb891054e0f90462fa3185f5d3af16d5e5ecf080d562154ae58819775dcf64c
View file https://github.com/Lellansin/deepcode-cli/blob/61dbcc897b1ce8f93a7bf68d60092429c4b00bff/src/common/openai-client.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/lessweb/deepcode-cli/pull/100/{{ revealButtonHref }}
src/ui/App.tsxhttps://github.com/lessweb/deepcode-cli/pull/100/files#diff-0022b32944774e72bcbec1b0520e753925073bfbeff256269d0f668f5f515b0e
View file https://github.com/Lellansin/deepcode-cli/blob/61dbcc897b1ce8f93a7bf68d60092429c4b00bff/src/ui/App.tsx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/lessweb/deepcode-cli/pull/100/{{ revealButtonHref }}
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-0022b32944774e72bcbec1b0520e753925073bfbeff256269d0f668f5f515b0e
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-0022b32944774e72bcbec1b0520e753925073bfbeff256269d0f668f5f515b0e
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-0022b32944774e72bcbec1b0520e753925073bfbeff256269d0f668f5f515b0e
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-0022b32944774e72bcbec1b0520e753925073bfbeff256269d0f668f5f515b0e
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-0022b32944774e72bcbec1b0520e753925073bfbeff256269d0f668f5f515b0e
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-0022b32944774e72bcbec1b0520e753925073bfbeff256269d0f668f5f515b0e
src/ui/index.tshttps://github.com/lessweb/deepcode-cli/pull/100/files#diff-8b9f572e7b966526733261e0898fc2731a8757c4427d099194655c1390aef48e
View file https://github.com/Lellansin/deepcode-cli/blob/61dbcc897b1ce8f93a7bf68d60092429c4b00bff/src/ui/index.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/lessweb/deepcode-cli/pull/100/{{ revealButtonHref }}
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-8b9f572e7b966526733261e0898fc2731a8757c4427d099194655c1390aef48e
https://github.com/lessweb/deepcode-cli/pull/100/files#diff-8b9f572e7b966526733261e0898fc2731a8757c4427d099194655c1390aef48e
Please reload this pagehttps://github.com/lessweb/deepcode-cli/pull/100/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.