René's URL Explorer Experiment


Title: improvement(db): cut hot-path connector count and rate-limit lock costs by waleedlatif1 · Pull Request #8944 · simstudioai/sim · GitHub

Open Graph Title: improvement(db): cut hot-path connector count and rate-limit lock costs by waleedlatif1 · Pull Request #8944 · simstudioai/sim

X Title: improvement(db): cut hot-path connector count and rate-limit lock costs by waleedlatif1 · Pull Request #8944 · simstudioai/sim

Description: Summary DbTokenBucket.consumeTokensAtomically now locks, refills, decides and spends every dimension in one CTE statement. Before, the bucket rows stayed locked across a separate UPDATE round trip per dimension plus the commit, and each waiter on a hot provider key queued behind that whole hold (waits ran 1.1–1.7 s with about 280 ms per holder). Now the lock is held for one statement plus the commit. The token arithmetic is the same float8 math consumeTokens does in JS, with refills on whole intervals. Refill and cooldowns are judged once every lock is held, as before. The statement advances the caller's clock by the lock wait it measures (clock_timestamp() sampled before the first row can reach the lock and again after a count over every locked row), so an uncontended admission decides at exactly the caller clock, so a contended waiter still refills the time it waited, and every stored instant stays on the application clock. The JS reader cross-checks the statement's own decision and spent count. On a mismatch, a vanished bucket, an abort, or a deadline passed after the statement, it throws inside the transaction so the spend rolls back. Once a connector has finished a pass (lastSyncAt set, which unfinished slices never advance), a content-pass slice that leaves the next pass unfinished no longer runs the full live document count. It keeps the count from that finished pass, which is the pass lastSyncAt still names. Until the first pass finishes, every slice is still counted, so a first sync shows progress. Finished passes count exactly as before, so the mass-deletion guard floor and the incremental listedCount are unchanged. Type of Change Performance improvement Testing provider-admission.integration.ts against real Postgres and Redis (bun run test:integration provider-admission): 20/20 pass. That includes the 40-way concurrent reversed-order admission, cooldown, cancel/expiry and partial-bucket cases, plus new cases: fractional refill on the atomic path; a waiter held behind another connection's row lock across a refill interval, which sees the refill and a wait measured from lock acquisition; and a spend rolled back when the deadline passes or the caller aborts while the statement runs. 23/23 pass. Each new case goes red with its guard removed (lock-wait clock, post-statement deadline check, post-statement abort check). Breaking the whole-interval refill anchoring turns the fractional case and 3 existing atomic cases red. lib/core/rate-limiter/** and sync-engine.test.ts: 221 pass. The new unfinished-slice count cases go red when the skip is reverted, and the first-pass later-slice case goes red without the lastSyncAt gate. Biome on the changed files. Type-check and check:audits are left to CI. Checklist Code follows project style guidelines Self-reviewed my changes Tests added/updated and passing (new tests pass the test-audit authoring gate) No new warnings introduced I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Open Graph Description: Summary DbTokenBucket.consumeTokensAtomically now locks, refills, decides and spends every dimension in one CTE statement. Before, the bucket rows stayed locked across a separate UPDATE round trip...

X Description: Summary DbTokenBucket.consumeTokensAtomically now locks, refills, decides and spends every dimension in one CTE statement. Before, the bucket rows stayed locked across a separate UPDATE round trip...

Opengraph URL: https://github.com/simstudioai/sim/pull/8944

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:ec91588b-41b5-984d-6625-e37e0f7afe42
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idEBF8:2B8D95:7DA9C5:B2ADCD:6AFB4D9E
html-safe-nonce7bf270eb55632336a546e31fdf4b5490ab1b7a5b5473dcf4c2959161c6a58f02
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQkY4OjJCOEQ5NTo3REE5QzU6QjJBRENEOjZBRkI0RDlFIiwidmlzaXRvcl9pZCI6IjQ4NDIwNTYyNjc3MDQ1MjAwOTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacb2761677c3a66f496a280964becbd2f2fdd9a1fee0c580e09c5ad4d007bbcb6c
hovercard-subject-tagpull_request:4835154756
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/simstudioai/sim/pull/8944/files
twitter:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/40672544?s=400&v=4
og:image:altSummary DbTokenBucket.consumeTokensAtomically now locks, refills, decides and spends every dimension in one CTE statement. Before, the bucket rows stayed locked across a separate UPDATE round trip...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneacf7616d06cc051644705b379878c9bb13dc5e70ecf4ffd9b34140f8ac01d7e1
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/simstudioai/sim git https://github.com/simstudioai/sim.git
octolytics-dimension-user_id199344406
octolytics-dimension-user_loginsimstudioai
octolytics-dimension-repository_id912559512
octolytics-dimension-repository_nwosimstudioai/sim
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id912559512
octolytics-dimension-repository_network_root_nwosimstudioai/sim
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
release26504db649b58525278f77a52b80ba5f10d5f4de
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/simstudioai/sim/pull/8944/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F8944%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fsimstudioai%2Fsim%2Fpull%2F8944%2Ffiles
Sign uphttps://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=simstudioai%2Fsim
Reloadhttps://github.com/simstudioai/sim/pull/8944/files
Reloadhttps://github.com/simstudioai/sim/pull/8944/files
Reloadhttps://github.com/simstudioai/sim/pull/8944/files
simstudioaihttps://github.com/simstudioai
simhttps://github.com/simstudioai/sim
Codehttps://github.com/simstudioai/sim
Issues129 (129)https://github.com/simstudioai/sim/issues
Pull requests197 (197)https://github.com/simstudioai/sim/pulls
Actionshttps://github.com/simstudioai/sim/actions
Projectshttps://github.com/simstudioai/sim/projects
Security and qualityhttps://github.com/simstudioai/sim/security
Insightshttps://github.com/simstudioai/sim/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fsimstudioai%2Fsim%2Fissues%2Fnew%2Fchoose
waleedlatif1https://github.com/waleedlatif1
staginghttps://github.com/simstudioai/sim/tree/staging
perf/hot-path-db-readshttps://github.com/simstudioai/sim/tree/perf/hot-path-db-reads
Conversation 22 https://github.com/simstudioai/sim/pull/8944
Commits 5 https://github.com/simstudioai/sim/pull/8944/commits
Checks 48 https://github.com/simstudioai/sim/pull/8944/checks
Files changed https://github.com/simstudioai/sim/pull/8944/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/8944/files
improvement(db): cut hot-path connector count and rate-limit lock costs https://github.com/simstudioai/sim/pull/8944/files#top
Show all changes 5 commits https://github.com/simstudioai/sim/pull/8944/files
fda1111 improvement(rate-limit): admit provider requests in one statement on … waleedlatif1 Oct 12, 2026 https://github.com/simstudioai/sim/pull/8944/commits/fda1111ca263cb03b94c458b498db7dd15f919bf
4542b2a improvement(connectors): skip the live document count on unfinished s… waleedlatif1 Oct 12, 2026 https://github.com/simstudioai/sim/pull/8944/commits/4542b2a6cf1030cd111d492ada1c35f88f8c762c
67ec3a8 fix(rate-limit): judge atomic admission at the moment the bucket lock… waleedlatif1 Oct 12, 2026 https://github.com/simstudioai/sim/pull/8944/commits/67ec3a8100f7dfa93b3f531dd38b6c745c2dadfd
aa1ed38 fix(rate-limit): count only the lock wait in the atomic admission clock waleedlatif1 Oct 12, 2026 https://github.com/simstudioai/sim/pull/8944/commits/aa1ed38a03f8e8306958e0e3a9e4130c175be837
ed2e401 fix(connectors): keep counting every slice until a connector's first … waleedlatif1 Oct 12, 2026 https://github.com/simstudioai/sim/pull/8944/commits/ed2e401c1a2ab32f3fa51976b92b0e8f4f9dc271
Clear filters https://github.com/simstudioai/sim/pull/8944/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/8944/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/8944/files
provider-admission.test.ts https://github.com/simstudioai/sim/pull/8944/files#diff-ed7166be6bffcab5ce98866b7dc35f07d72928f9abfafc20f568c64844af5dff
db-token-bucket.test.ts https://github.com/simstudioai/sim/pull/8944/files#diff-8da497c377baab97c946ced9be8fe6687892866095daeb4574d850d2aac98ba0
db-token-bucket.ts https://github.com/simstudioai/sim/pull/8944/files#diff-86e06f6d7b95b70d8f6f6b77ad543ed5fd71092ce7cf08251d994488bd28ce88
provider-admission.integration.ts https://github.com/simstudioai/sim/pull/8944/files#diff-b83900c27a5befa3a7826306c4b0080f69e75bd781fac0a9b3db7729a4e1c606
sync-engine.test.ts https://github.com/simstudioai/sim/pull/8944/files#diff-021afebf7e100833ecdc940e307263436964ce85ef3dfd40fc90307a1d115534
sync-engine.ts https://github.com/simstudioai/sim/pull/8944/files#diff-277f76464f02682e44e6de58ebd215c927f0f6a3a7165af669a0717b593790e9
apps/sim/lib/core/rate-limiter/provider-admission.test.tshttps://github.com/simstudioai/sim/pull/8944/files#diff-ed7166be6bffcab5ce98866b7dc35f07d72928f9abfafc20f568c64844af5dff
View file https://github.com/simstudioai/sim/blob/ed2e401c1a2ab32f3fa51976b92b0e8f4f9dc271/apps/sim/lib/core/rate-limiter/provider-admission.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/8944/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/8944/files#diff-ed7166be6bffcab5ce98866b7dc35f07d72928f9abfafc20f568c64844af5dff
https://github.com/simstudioai/sim/pull/8944/files#diff-ed7166be6bffcab5ce98866b7dc35f07d72928f9abfafc20f568c64844af5dff
https://github.com/simstudioai/sim/pull/8944/files#diff-ed7166be6bffcab5ce98866b7dc35f07d72928f9abfafc20f568c64844af5dff
apps/sim/lib/core/rate-limiter/storage/db-token-bucket.test.tshttps://github.com/simstudioai/sim/pull/8944/files#diff-8da497c377baab97c946ced9be8fe6687892866095daeb4574d850d2aac98ba0
View file https://github.com/simstudioai/sim/blob/ed2e401c1a2ab32f3fa51976b92b0e8f4f9dc271/apps/sim/lib/core/rate-limiter/storage/db-token-bucket.test.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/8944/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/8944/files#diff-8da497c377baab97c946ced9be8fe6687892866095daeb4574d850d2aac98ba0
https://github.com/simstudioai/sim/pull/8944/files#diff-8da497c377baab97c946ced9be8fe6687892866095daeb4574d850d2aac98ba0
apps/sim/lib/core/rate-limiter/storage/db-token-bucket.tshttps://github.com/simstudioai/sim/pull/8944/files#diff-86e06f6d7b95b70d8f6f6b77ad543ed5fd71092ce7cf08251d994488bd28ce88
View file https://github.com/simstudioai/sim/blob/ed2e401c1a2ab32f3fa51976b92b0e8f4f9dc271/apps/sim/lib/core/rate-limiter/storage/db-token-bucket.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/simstudioai/sim/pull/8944/{{ revealButtonHref }}
https://github.com/simstudioai/sim/pull/8944/files#diff-86e06f6d7b95b70d8f6f6b77ad543ed5fd71092ce7cf08251d994488bd28ce88
Please reload this pagehttps://github.com/simstudioai/sim/pull/8944/files
https://github.com/simstudioai/sim/pull/8944/files#diff-86e06f6d7b95b70d8f6f6b77ad543ed5fd71092ce7cf08251d994488bd28ce88
https://github.com/simstudioai/sim/pull/8944/files#diff-86e06f6d7b95b70d8f6f6b77ad543ed5fd71092ce7cf08251d994488bd28ce88
https://github.com/simstudioai/sim/pull/8944/files#diff-86e06f6d7b95b70d8f6f6b77ad543ed5fd71092ce7cf08251d994488bd28ce88
https://github.com/simstudioai/sim/pull/8944/files#diff-86e06f6d7b95b70d8f6f6b77ad543ed5fd71092ce7cf08251d994488bd28ce88
Please reload this pagehttps://github.com/simstudioai/sim/pull/8944/files
Please reload this pagehttps://github.com/simstudioai/sim/pull/8944/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.