Skip to content

perf: replace management-path locks with moka concurrent cache#114

Merged
Itsusinn merged 3 commits into
mainfrom
perf/loose-lock
May 4, 2026
Merged

perf: replace management-path locks with moka concurrent cache#114
Itsusinn merged 3 commits into
mainfrom
perf/loose-lock

Conversation

@Itsusinn
Copy link
Copy Markdown
Owner

@Itsusinn Itsusinn commented May 4, 2026

Changes

Replace management paths with for lock-free concurrent access.

Itsusinn added 3 commits May 4, 2026 22:48
- Replace server Connection::udp_sessions from AsyncRwLock<HashMap> to
  moka::future::Cache, removing Weak/upgrade overhead
- Replace client socks5_udp_sessions and fwd_udp_sessions from
  AsyncRwLock<HashMap> to moka::future::Cache
- All operations (get/insert/remove/invalidate) are now lock-free

Assisted-by: OpenClaw:deepseek-v4-flash
Change Cache<u16, Arc<UdpSession>> back to Cache<u16, Weak<UdpSession>>
to break the strong reference cycle that could prevent memory from being
freed:

  Cache -> Arc<UdpSession> -> conn: Connection -> Cache (same internal data)

With Weak, the UdpSession lifetime is controlled by the listen task
(which holds Arc), not the cache entry.

Assisted-by: OpenClaw:deepseek-v4-flash
UdpSession no longer stores . Instead it only keeps
a  handle (for cleanup) and receives the
Connection directly for relay_packet at spawn time. This breaks the
strong reference cycle:

  Cache -> Arc<UdpSession> -> conn: Connection -> Cache

Now: Cache -> Arc<UdpSession> -> cache handle (shared ptr)

Cache entries are now  instead of ,
eliminating all upgrade() overhead.

Assisted-by: OpenClaw:deepseek-v4-flash
@Itsusinn Itsusinn merged commit 6debab3 into main May 4, 2026
21 checks passed
@Itsusinn Itsusinn deleted the perf/loose-lock branch May 4, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant