mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6758] [MERGED] perf(sub): cache each inbound's settings without clients for subscription bodies #6441
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6441
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6758
Author: @amirim1
Created: 10/7/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei
Base:
main← Head:feat/sub-data-cache📝 Commits (10+)
178c6c8feat(sub): cache per-subscription data reads for subscription bodies9c6e4b7feat(sub): invalidate subscription snapshots on panel mutations81c4e1bMerge remote-tracking branch 'origin/main' into feat/sub-data-cache17e43a5Merge remote-tracking branch 'origin/main' into feat/sub-data-cacheac6e928Merge origin/main into feat/sub-data-cached2e3ab0sub: fix shadowed inbounds in getInboundsBySubId else branch; gofmt945731cMerge remote-tracking branch 'origin/main' into pr/6758efb05f0fix(sub): release the snapshot cache with the subscription serverfc87225style(sub): fit the snapshot cache comments in two linesb9246e5refactor(sub): cache each inbound's settings without its clients, not each subscriber📊 Changes
13 files changed (+469 additions, -13 deletions)
View changed files
📝
go.mod(+1 -1)📝
internal/sub/controller.go(+10 -1)📝
internal/sub/service.go(+57 -11)➕
internal/sub/settings_cache.go(+103 -0)➕
internal/sub/settings_cache_test.go(+244 -0)📝
internal/sub/sub.go(+3 -0)📝
internal/web/service/client_bulk.go(+1 -0)📝
internal/web/service/client_inbound_apply.go(+4 -0)📝
internal/web/service/inbound.go(+6 -0)📝
internal/web/service/inbound_disable.go(+2 -0)📝
internal/web/service/inbound_node.go(+3 -0)📝
internal/web/service/inbound_settings_commit.go(+1 -0)➕
internal/web/service/sub_data_invalidation.go(+34 -0)📄 Description
Summary
Subscription bodies (
/sub/,/json/,/clash/) no longer read and scan each inbound's whole settings blob on every fetch. Each inbound's settings, minus itsclientsarray, are cached in memory, keyed by inbound and shared by every subscriber of that inbound.Why
On a large inbound the settings blob holds every client: about 25 MB at 100k clients. A profile of one subscription fetch at that size put about 57% of the time in reading that column and about 27% in scanning its
clientsarray. Subscription bodies never use that array; they resolve their clients from theclientstable (GetClientsBySubId). So every subscriber of the inbound paid for the whole blob on every poll.Design
settingscolumn omitted. The subscriber's clients, traffic stats and hosts are read fresh, as before.internal/web/service/sub_data_invalidation.go), which is hooked into the inbound and client mutations. A 10 s TTL bounds anything that bypasses those services. A load that overlaps a purge is served once but not kept.NewSUBController), andServer.Stopreleases its invalidator. Panel link and QR rendering read fresh and register nothing.Benchmark
The
internal/subscale dataset: a 3-client subscriber inside one inbound holding N clients. Each figure is the average of 20 fetches, all on the same machine.For this dataset the cache holds one 21-byte string per inbound.
An earlier revision of this PR cached each subscriber's full inbound rows, and this design replaces it. At 100k clients one of its entries was 25 MB, a hit was slower than no cache on SQLite (110 ms vs 72 ms), and 30 subscribers within the TTL held about 840 MB.
Type of change
Areas affected
How was this tested?
internal/sub/settings_cache_test.gocovers the following:InvalidateSubData.Each of these tests fails when the behavior it guards is removed.
go test ./internal/sub/ -race, theinternal/web/servicesuite andgolangci-lintall pass.Screenshots / recordings
N/A (no UI changes).
Breaking changes
None. A settings change made by a path that bypasses the panel's services can reach subscription bodies up to 10 s late. Ports, enable state, clients and traffic are never cached.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.